Part II: Programming Microsoft Access
462
The Report_NoData event illustrated in Figure 12.3 first displays a message box to advise the
user that the report contains no data. Then the event procedure cancels the report’s opening by
setting the Cancel parameter to True. Because the Cancel parameter is set to True, the report
never appears on the screen and is not sent to the printer.
Many Access events are accompanied by parameters, such as the Cancel parameter you see in
Figure 12.3. In this case, setting Cancel to True instructs Access to simply ignore the process
that triggered the event. Because NoData was triggered as part of the report’s opening process, set-
ting Cancel to True prevents the report from being sent to the printer or being displayed on the
screen. You’ll see many examples of event property procedure parameters throughout this book.
Report section event procedures
In addition to the event properties for the form itself, Access offers three specialized event proper-
ties to use with report sections. Table 12.7 shows each property, the event it recognizes, and how
it works.
TABLE 12.7
Report Section Events
Event When the Event Is Triggered
Format When the section is pre-formatted in memory before being sent to the printer. This is your
opportunity to apply special formatting to controls within the section.
Print As the section is sent to the printer. It is too late to format controls in a report section when the
Print event fires.
Retreat After the Format event but before the Print event. Occurs when Access has to back up past
other sections on a page to perform multiple formatting passes. Retreat is included in all
sections except headers and footers.
The Format event
Use the Format event to apply special formatting to controls within a section before the section is
printed. Format is useful, for example, to hide controls you don’t want to print because of some
condition in the report’s data. The event procedure runs as Access lays out the section in memory
but before the report is sent to the printer.
You can set the On Format and On Print event properties for any section of the report.
However, OnRetreat is not available for the page header or page footer sections. Figure 12.4
shows the Property Sheet for the report’s On NoData event property. Notice that the drop-down
list at the top of the Property Sheet shows that the report is selected, so the events in the Event tab
relate to the report itself and not an individual control on the report.