报告 对象涉及特定的 Microsoft Access 报表。
备注
Report 对象是 Reports 集合的成员,该集合是当前打开的所有报表的集合。 在 报表 集合中从零开始索引单独报告。 通过按名称引用报表或引用其集合中的索引来引用 Reports 集合中的单个 Report 对象。 如果报表名称包含空格,那么该名称必须用方括号 ([ ]) 括起来。
| 语法 | 示例 | 
|---|---|
| 报告!reportname | 报告!OrderReport | 
| 报告![报表名称] | Reports![Order Report] | 
| 报表 (“reportname”) | 报表 (“OrderReport”) | 
| 报表 (索引) | Reports(0) | 
注意
[!注释] 报表 中的每个对象有一个 控件 集合,其中包含在报表上的所有控件。 通过隐式或显式引用 Controls 集合来引用报表上的控件。 如果隐式引用 Controls 集合,代码运行速度更快。 下面的示例演示两个您可能参考名 其为称为 订单报表报表上的控件的方法。
' Implicit reference. 
Reports!OrderReport!NewData
' Explicit reference. 
Reports!OrderReport.Controls!NewData
示例
以下示例演示如何使用报表的 NoData 事件来防止在没有要显示的数据时打开报表。
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事件向报表中添加一个水印,在打印前。
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属性设置。
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
下面的示例演示如何设置格式报表以显示进度栏。 该示例使用一对矩形控件、 boxInside和 boxOutside,若要创建基于 AvgOfRating的值的进度栏。 仅在 打印预览模式下打开该报告或打印时,进度栏是可见的。
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
事件
- Activate
- ApplyFilter
- Click
- Close
- Current
- DblClick
- Deactivate
- Error
- Filter
- GotFocus
- KeyDown
- KeyPress
- KeyUp
- Load
- LostFocus
- MouseDown
- MouseMove
- MouseUp
- MouseWheel
- NoData
- Open
- Page
- Resize
- Timer
- Unload
方法
属性
- ActiveControl
- AllowLayoutView
- AllowReportView
- 应用程序
- AutoCenter
- AutoResize
- BorderStyle
- Caption
- CloseButton
- ControlBox
- Controls
- Count
- CurrentRecord
- CurrentView
- CurrentX
- CurrentY
- Cycle
- DateGrouping
- DefaultControl
- DefaultView
- Dirty
- DisplayOnSharePointSite
- DrawMode
- DrawStyle
- DrawWidth
- FastLaserPrinting
- FillColor
- FillStyle
- Filter
- FilterOn
- FilterOnLoad
- FitToPage
- FontBold
- FontItalic
- FontName
- FontSize
- FontUnderline
- ForeColor
- FormatCount
- GridX
- GridY
- GroupLevel
- GrpKeepTogether
- HasData
- HasModule
- Height
- HelpContextId
- HelpFile
- Hwnd
- InputParameters
- KeyPreview
- LayoutForPrint
- Left
- MenuBar
- MinMaxButtons
- Modal
- Module
- MouseWheel
- Moveable
- MoveLayout
- 名称
- NextRecord
- OnActivate
- OnApplyFilter
- OnClick
- OnClose
- OnCurrent
- OnDblClick
- OnDeactivate
- OnError
- OnFilter
- OnGotFocus
- OnKeyDown
- OnKeyPress
- OnKeyUp
- OnLoad
- OnLostFocus
- OnMouseDown
- OnMouseMove
- OnMouseUp
- OnNoData
- OnOpen
- OnPage
- OnResize
- OnTimer
- OnUnload
- OpenArgs
- OrderBy
- OrderByOn
- OrderByOnLoad
- Orientation
- Page
- PageFooter
- PageHeader
- Pages
- Painting
- PaintPalette
- PaletteSource
- Parent
- Picture
- PictureAlignment
- PictureData
- PicturePages
- PicturePalette
- PictureSizeMode
- PictureTiling
- PictureType
- PopUp
- PrintCount
- Printer
- PrintSection
- Properties
- PrtDevMode
- PrtDevNames
- PrtMip
- RecordLocks
- Recordset
- RecordSource
- RecordSourceQualifier
- 报告
- RibbonName
- ScaleHeight
- ScaleLeft
- ScaleMode
- ScaleTop
- ScaleWidth
- ScrollBars
- Section
- ServerFilter
- Shape
- ShortcutMenuBar
- ShowPageMargins
- Tag
- TimerInterval
- Toolbar
- Top
- UseDefaultPrinter
- Visible
- Width
- WindowHeight
- WindowLeft
- WindowTop
- WindowWidth
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。