Chapter 12: The Access Event Model
461
Attaching an event procedure to the report runs code whenever the report opens, closes, or prints.
Each section in a report (header, footer, and so on) also includes events that run as the report is
formatted or printed.
Several overall report event properties are available. Table 12.6 shows the Access report events. As
you can see, the list of report events is much shorter than the form event list.
TABLE 12.6
Report Events
Event Property When the Event Is Triggered
Open When the report opens but before printing
Close When the report closes and is removed from the screen
Activate When the report receives the focus and becomes the active window
Deactivate When a different window becomes active
NoData When no data is passed to the report as it opens
Page When the report changes pages
Error When a runtime error is produced in Access
Even though users do not interact with reports as they do with forms, events still play a vital role
in report design. Opening a report containing no data generally yields erroneous results. The
report may display a title and no detail information. Or, it may display #error values for missing
information. This situation can be a little scary for the user. Use the NoData event to inform the
user that the report contains no data. NoData fires as a report opens and there is no data available
in the report’s RecordSource. Use the NoData event procedure to display a message box
describing the situation to the user and then cancel the report’s opening. Figure 12.3 shows a typi-
cal NoData event procedure.
FIGURE 12.3
Running a NoData event procedure when there is no data for a report