Report 对象 (Access)Report object (Access)
报告 对象涉及特定的 Microsoft Access 报表。A Report object refers to a particular Microsoft Access report.
备注Remarks
Report对象是**Reports** 集合的一个成员, 该集合是所有当前打开的报表的集合。A Report object is a member of the Reports collection, which is a collection of all currently open reports. 在 报表 集合中从零开始索引单独报告。Within the Reports collection, individual reports are indexed beginning with zero. 您可以参考 报表 集合,方法是︰ 按名称,或在集合中的索引引用引用报告中的单个 报表 对象。You can refer to an individual Report object in the Reports collection either by referring to the report by name, or by referring to its index within the collection. 如果报表名称包含空格,那么该名称必须用方括号 ([ ]) 括起来。If the report name includes a space, the name must be surrounded by brackets ([ ]).
语法Syntax | 示例Example |
---|---|
报告!reportnameReports!reportname | Reports!订单报表报表Reports!OrderReport |
报告![报告名称]Reports![report name] | Reports![Order Report]Reports![Order Report] |
报告("reportname")Reports("reportname") | Reports ("订单报表报表")Reports("OrderReport") |
报告(索引)Reports(index) | Reports(0)Reports(0) |
备注
[!注释] 报表 中的每个对象有一个 控件 集合,其中包含在报表上的所有控件。Each Report object has a Controls collection, which contains all controls on the report. 您可以参考报表上的控件可以通过隐式或显式引用 Controls 集合。You can refer to a control on a report either by implicitly or explicitly referring to the Controls collection. 您的代码将更快如果隐式引用的 控件 集合。Your code will be faster if you refer to the Controls collection implicitly. 下面的示例演示两个您可能参考名 其为称为 订单报表报表上的控件的方法。The following examples show two of the ways you might refer to a control named NewData on a report called OrderReport.
' Implicit reference.
Reports!OrderReport!NewData
' Explicit reference.
Reports!OrderReport.Controls!NewData
示例Example
下面的示例演示如何使用报表的NoData事件来防止在没有要显示的数据时打开报表。The following example shows how to use the NoData event of a report to prevent the report from opening when there is no data to be displayed.
Private Sub Report_NoData(Cancel As Integer)
'Add code here that will be executed if no data
'was returned by the Report's RecordSource
MsgBox "No customers ordered this product this month. " & _
"The report will now close."
Cancel = True
End Sub
下面的示例演示如何使用 Page事件向报表中添加一个水印,在打印前。The following example shows how to use the Page event to add a watermark to a report before it is printed.
Private Sub Report_Page()
Dim strWatermarkText As String
Dim sizeHor As Single
Dim sizeVer As Single
#If RUN_PAGE_EVENT = True Then
With Me
'// Print page border
Me.Line (0, 0)-(.ScaleWidth - 1, .ScaleHeight - 1), vbBlack, B
'// Print watermark
strWatermarkText = "Confidential"
.ScaleMode = 3
.FontName = "Segoe UI"
.FontSize = 48
.ForeColor = RGB(255, 0, 0)
'// Calculate text metrics
sizeHor = .TextWidth(strWatermarkText)
sizeVer = .TextHeight(strWatermarkText)
'// Set the print location
.CurrentX = (.ScaleWidth / 2) - (sizeHor / 2)
.CurrentY = (.ScaleHeight / 2) - (sizeVer / 2)
'// Print the watermark
.Print strWatermarkText
End With
#End If
End Sub
下面的示例演示如何将基于它的值的控件的 BackColor属性设置。The following example shows how to set the BackColor property of a control based on its value.
Private Sub SetControlFormatting()
If (Me.AvgOfRating >= 8) Then
Me.AvgOfRating.BackColor = vbGreen
ElseIf (Me.AvgOfRating >= 5) Then
Me.AvgOfRating.BackColor = vbYellow
Else
Me.AvgOfRating.BackColor = vbRed
End If
End Sub
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' size the width of the rectangle
Dim lngOffset As Long
lngOffset = (Me.boxInside.Left - Me.boxOutside.Left) * 2
Me.boxInside.Width = (Me.boxOutside.Width * (Me.AvgOfRating / 10)) - lngOffset
' do conditional formatting for the control in print preview
SetControlFormatting
End Sub
Private Sub Detail_Paint()
' do conditional formatting for the control in report view
SetControlFormatting
End Sub
下面的示例演示如何设置格式报表以显示进度栏。The following example shows how to format a report to show progress bars. 该示例使用一对矩形控件、 boxInside和 boxOutside,若要创建基于 AvgOfRating的值的进度栏。The example uses a pair of rectangle controls, boxInside and boxOutside, to create a progress bar based on the value of AvgOfRating. 仅在 打印预览模式下打开该报告或打印时,进度栏是可见的。The progress bars are visible only when the report is opened in Print Preview mode or it is printed.
Private Sub Report_Load()
If (Me.CurrentView = AcCurrentView.acCurViewPreview) Then
Me.boxInside.Visible = True
Me.boxOutside.Visible = True
Else
Me.boxInside.Visible = False
Me.boxOutside.Visible = False
End If
End Sub
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' size the width of the rectangle
Dim lngOffset As Long
lngOffset = (Me.boxInside.Left - Me.boxOutside.Left) * 2
Me.boxInside.Width = (Me.boxOutside.Width * (Me.AvgOfRating / 10)) - lngOffset
' do conditional formatting for the control in print preview
SetControlFormatting
End Sub
事件Events
- ActivateActivate
- ApplyFilterApplyFilter
- ClickClick
- CloseClose
- CurrentCurrent
- DblClickDblClick
- DeactivateDeactivate
- ErrorError
- FilterFilter
- GotFocusGotFocus
- KeyDownKeyDown
- KeyPressKeyPress
- KeyUpKeyUp
- LoadLoad
- LostFocusLostFocus
- MouseDownMouseDown
- MouseMoveMouseMove
- MouseUpMouseUp
- MouseWheelMouseWheel
- NoDataNoData
- OpenOpen
- PagePage
- ResizeResize
- TimerTimer
- UnloadUnload
方法Methods
- CircleCircle
- LineLine
- MoveMove
- PrintPrint
- PSetPSet
- RequeryRequery
- 小数位数Scale
- TextHeightTextHeight
- TextWidthTextWidth
属性Properties
- ActiveControlActiveControl
- AllowLayoutViewAllowLayoutView
- AllowReportViewAllowReportView
- 应用程序Application
- AutoCenterAutoCenter
- AutoResizeAutoResize
- BorderStyleBorderStyle
- CaptionCaption
- CloseButtonCloseButton
- ControlBoxControlBox
- ControlsControls
- CountCount
- CurrentRecordCurrentRecord
- CurrentViewCurrentView
- CurrentXCurrentX
- CurrentYCurrentY
- CycleCycle
- DateGroupingDateGrouping
- DefaultControlDefaultControl
- DefaultViewDefaultView
- DirtyDirty
- DisplayOnSharePointSiteDisplayOnSharePointSite
- DrawModeDrawMode
- DrawStyleDrawStyle
- DrawWidthDrawWidth
- FastLaserPrintingFastLaserPrinting
- FillColorFillColor
- FillStyleFillStyle
- FilterFilter
- FilterOnFilterOn
- FilterOnLoadFilterOnLoad
- FitToPageFitToPage
- FontBoldFontBold
- FontItalicFontItalic
- FontNameFontName
- FontSizeFontSize
- FontUnderlineFontUnderline
- ForeColorForeColor
- FormatCountFormatCount
- GridXGridX
- GridYGridY
- GroupLevelGroupLevel
- GrpKeepTogetherGrpKeepTogether
- HasDataHasData
- HasModuleHasModule
- HeightHeight
- HelpContextIdHelpContextId
- HelpFileHelpFile
- HwndHwnd
- InputParametersInputParameters
- KeyPreviewKeyPreview
- LayoutForPrintLayoutForPrint
- LeftLeft
- MenuBarMenuBar
- MinMaxButtonsMinMaxButtons
- ModalModal
- ModuleModule
- MouseWheelMouseWheel
- MoveableMoveable
- MoveLayoutMoveLayout
- 名称Name
- NextRecordNextRecord
- OnActivateOnActivate
- OnApplyFilterOnApplyFilter
- OnClickOnClick
- OnCloseOnClose
- OnCurrentOnCurrent
- OnDblClickOnDblClick
- OnDeactivateOnDeactivate
- OnErrorOnError
- OnFilterOnFilter
- OnGotFocusOnGotFocus
- OnKeyDownOnKeyDown
- OnKeyPressOnKeyPress
- OnKeyUpOnKeyUp
- OnLoadOnLoad
- OnLostFocusOnLostFocus
- OnMouseDownOnMouseDown
- OnMouseMoveOnMouseMove
- OnMouseUpOnMouseUp
- OnNoDataOnNoData
- OnOpenOnOpen
- OnPageOnPage
- OnResizeOnResize
- OnTimerOnTimer
- OnUnloadOnUnload
- OpenArgsOpenArgs
- OrderByOrderBy
- OrderByOnOrderByOn
- OrderByOnLoadOrderByOnLoad
- OrientationOrientation
- PagePage
- PageFooterPageFooter
- PageHeaderPageHeader
- PagesPages
- PaintingPainting
- PaintPalettePaintPalette
- PaletteSourcePaletteSource
- ParentParent
- PicturePicture
- PictureAlignmentPictureAlignment
- PictureDataPictureData
- PicturePagesPicturePages
- PicturePalettePicturePalette
- PictureSizeModePictureSizeMode
- PictureTilingPictureTiling
- PictureTypePictureType
- PopUpPopUp
- PrintCountPrintCount
- PrinterPrinter
- PrintSectionPrintSection
- PropertiesProperties
- PrtDevModePrtDevMode
- PrtDevNamesPrtDevNames
- PrtMipPrtMip
- RecordLocksRecordLocks
- RecordsetRecordset
- RecordSourceRecordSource
- RecordSourceQualifierRecordSourceQualifier
- 报告Report
- RibbonNameRibbonName
- ScaleHeightScaleHeight
- ScaleLeftScaleLeft
- ScaleModeScaleMode
- ScaleTopScaleTop
- ScaleWidthScaleWidth
- ScrollBarsScrollBars
- SectionSection
- ServerFilterServerFilter
- ShapeShape
- ShortcutMenuBarShortcutMenuBar
- ShowPageMarginsShowPageMargins
- TagTag
- TimerIntervalTimerInterval
- ToolbarToolbar
- TopTop
- UseDefaultPrinterUseDefaultPrinter
- VisibleVisible
- WidthWidth
- WindowHeightWindowHeight
- WindowLeftWindowLeft
- WindowTopWindowTop
- WindowWidthWindowWidth
另请参阅See also
支持和反馈Support and feedback
有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.