Report Object

Description

A Report object refers to a particular Microsoft Access report.

Remarks

A Report object is a member of the Reports collection. Within the Reports collection, individual reports are numbered by an index 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

Reports!reportname

Reports!OrderReport

Reports![report name]

Reports![Order Report]

Reports("reportname")

Reports("OrderReport")

Reports(index)

Reports(0)


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 NewData control on a report called OrderReport.


Reports!OrderReport!NewData           ' Implicit reference.


Reports!OrderReport.Controls!NewData       ' Explicit reference.

Many of the properties of a Report object can also be set from a report’s property sheet. For information on how to set individual properties, see those properties.

You can’t add or delete a Report object from the Reports collection.

Properties

ActiveControl Property, ActiveReport Property.

See Also

Controls Collection, Reports Collection.

Example

The following example creates a new report and sets certain properties.


Sub NewReport()
    Dim rpt As Report


    ' Return variable of data type Report pointing to new Report object.
    Set rpt = CreateReport
    ' Set properties for new report.
    rpt.RecordSource = "Products"
    rpt.Caption = "Products Report"
    ' Restore new report.
    DoCmd.RestoreSub



The next example enumerates the Reports collection and prints the name of each report in the Reports collection. It then enumerates the Controls collection of each report and prints the name of each control on the report.


Sub AllOpenReports()
    Dim rpt As Report, ctl As Control

    ' Enumerate Reports collection.
    For Each rpt In Reports
        ' Print name of report.
        Debug.Print rpt.Name
        ' Enumerate Controls collection of each report.
        For Each ctl In rpt.Controls
            ' Print name of each control.
            Debug.Print ">>>"; ctl.Name
        Next ctl
    Next rptSub