Report Object, 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.
    With rpt
        .RecordSource = "Products"
        .Caption = "Products Report"
    End With
    ' Restore new report.
    DoCmd.Restore
End Sub

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 rpt
End Sub