Table of contents
TOC
折叠目录
展开目录

报告对象 (访问)Report Object (Access)

office 365 dev account|上次更新日期: 2018/4/3
|
2 参与人员

报告 对象涉及特定的 Microsoft Access 报表。A Report object refers to a particular Microsoft Access report.

注解Remarks

报告 对象是 报告 集合,它是所有当前打开的报表的集合的成员。在 报表 集合中从零开始索引单独报告。您可以参考 报表 集合,方法是︰ 按名称,或在集合中的索引引用引用报告中的单个 报表 对象。如果报表名称包含空格,必须将名称用方括号 ([]) 括。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!OrderReport
报告 ![ report name] Reports ![ report name]Reports![Order Report]Reports![Order Report]
报告 (" reportname")Reports (" reportname")Reports("OrderReport")Reports("OrderReport")
报告 ( index)Reports ( index)Reports(0)Reports(0)
注意

[!注释] 报表 中的每个对象有一个 控件 集合,其中包含在报表上的所有控件。您可以参考报表上的控件可以通过隐式或显式引用 Controls 集合。您的代码将更快如果隐式引用的 控件 集合。下面的示例演示两个您可能参考名 为称为 订单报表报表上的控件的方法。Each Report object has a Controls collection, which contains all controls on the report. 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 form opening when there is no data to be displayed.

示例代码提供方:Microsoft Access 2010 程序员参考Sample code provided by: The Microsoft Access 2010 Programmer's Reference

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


下面的示例演示如何设置格式报表以显示进度栏。该示例使用一对矩形控件、 boxInsideboxOutside,若要创建基于 AvgOfRating的值的进度栏。仅在 打印预览模式下打开该报告或打印时,进度栏是可见的。The following example shows how to format a report to show progress bars. 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

名称Name
激活Activate
ApplyFilterApplyFilter
单击Click
关闭Close
当前Current
DblClickDblClick
停用Deactivate
错误Error
筛选Filter
GotFocusGotFocus
KeyDownKeyDown
KeyPressKeyPress
KeyUpKeyUp
加载Load
LostFocusLostFocus
MouseDownMouseDown
MouseMoveMouseMove
MouseUpMouseUp
MouseWheelMouseWheel
无数据NoData
打开Open
页面Page
调整大小Resize
计时器Timer
卸载Unload

方法Methods

名称Name
圆形Circle
线条Line
移动Move
打印Print
PSetPSet
重新查询Requery
小数位数Scale
TextHeightTextHeight
TextWidthTextWidth

属性Properties

名称Name
ActiveControlActiveControl
AllowLayoutViewAllowLayoutView
AllowReportViewAllowReportView
应用程序Application
AutoCenterAutoCenter
AutoResizeAutoResize
BorderStyleBorderStyle
标题Caption
CloseButtonCloseButton
ControlBoxControlBox
ControlsControls
计数Count
CurrentRecordCurrentRecord
CurrentViewCurrentView
CurrentXCurrentX
当前CurrentY
周期Cycle
DateGroupingDateGrouping
DefaultControlDefaultControl
DefaultViewDefaultView
DirtyDirty
DisplayOnSharePointSiteDisplayOnSharePointSite
DrawModeDrawMode
DrawStyle
DrawWidthDrawWidth
FastLaserPrintingFastLaserPrinting
FillColorFillColor
FillStyleFillStyle
筛选Filter
FilterOnFilterOn
FilterOnLoadFilterOnLoad
FitToPageFitToPage
FontBoldFontBold
FontItalicFontItalic
FontNameFontName
FontSizeFontSize
FontUnderlineFontUnderline
ForeColorForeColor
FormatCountFormatCount
GridXGridX
GridYGridY
GroupLevelGroupLevel
组结合方式GrpKeepTogether
HasDataHasData
HasModuleHasModule
高度Height
HelpContextIdHelpContextId
HelpFileHelpFile
HwndHwnd
InputParametersInputParameters
KeyPreviewKeyPreview
LayoutForPrintLayoutForPrint
向左Left
MenuBarMenuBar
MinMaxButtonsMinMaxButtons
ModalModal
模块Module
MouseWheelMouseWheel
移动Moveable
MoveLayoutMoveLayout
名称Name
NextRecordNextRecord
OnActivateOnActivate
OnApplyFilterOnApplyFilter
OnClickOnClick
OnCloseOnClose
OnCurrentOnCurrent
OnDblClickOnDblClick
OnDeactivateOnDeactivate
OnErrorOnError
OnFilterOnFilter
OnGotFocusOnGotFocus
OnKeyDownOnKeyDown
OnKeyPressOnKeyPress
OnKeyUpOnKeyUp
OnLoadOnLoad
OnLostFocusOnLostFocus
OnMouseDownOnMouseDown
OnMouseMoveOnMouseMove
OnMouseUpOnMouseUp
无数据OnNoData
OnOpenOnOpen
OnPageOnPage
OnResizeOnResize
OnTimerOnTimer
OnUnloadOnUnload
OpenArgsOpenArgs
OrderByOrderBy
OrderByOnOrderByOn
OrderByOnLoadOrderByOnLoad
OrientationOrientation
页面Page
页面页脚PageFooter
页面页眉PageHeader
页面Pages
PaintingPainting
PaintPalettePaintPalette
PaletteSourcePaletteSource
父级Parent
PicturePicture
PictureAlignmentPictureAlignment
PictureDataPictureData
图片PicturePages
PicturePalettePicturePalette
PictureSizeModePictureSizeMode
PictureTilingPictureTiling
PictureTypePictureType
PopUpPopUp
变动PrintCount
打印机Printer
PrintSectionPrintSection
属性Properties
PrtDevModePrtDevMode
PrtDevNamesPrtDevNames
PrtMipPrtMip
RecordLocksRecordLocks
记录集Recordset
RecordSourceRecordSource
RecordSourceQualifierRecordSourceQualifier
报表Report
RibbonNameRibbonName
ScaleHeightScaleHeight
ScaleLeftScaleLeft
ScaleModeScaleMode
距离ScaleTop
ScaleWidthScaleWidth
ScrollBarsScrollBars
Section
ServerFilterServerFilter
形状Shape
ShortcutMenuBarShortcutMenuBar
ShowPageMarginsShowPageMargins
标记Tag
TimerIntervalTimerInterval
工具栏Toolbar
返回页首Top
UseDefaultPrinterUseDefaultPrinter
可见Visible
WidthWidth
WindowHeightWindowHeight
WindowLeftWindowLeft
WindowTopWindowTop
WindowWidthWindowWidth

关于参与者About the contributors

Wrox Press 秉承程序员到程序员的理念。Wrox 书籍由程序员为程序员编写,Wrox 品牌意味着对实际编程问题的权威解决方案。Wrox Press is driven by the Programmer to Programmer philosophy. Wrox books are written by programmers for programmers, and the Wrox brand means authoritative solutions to real-world programming problems.

另请参阅See also

报告对象成员访问对象模型引用Report Object MembersAccess Object Model Reference

© 2018 Microsoft