To create an event procedure that is executed when the NoData event occurs, set the OnNoData property to [Event Procedure], and click the Build button.
Private Sub Report_NoData(Cancel As Integer)
The NoData event procedure uses the following argument.
Argument |
Description |
Cancel |
The setting determining whether to print the report. Setting Cancel to True (-1) prevents the report from printing. You can also use the CancelEvent method of the DoCmd object to cancel printing the report. |
NoData Event — Macros.
The following example shows how to cancel printing a report when it is blank. A message box notifying the user that the printing has been canceled is also displayed.
Private Sub Report_NoData(Cancel As Integer) MsgBox "The report has no data." & _ "@Printing the report is canceled. " & _ "@Check the source of data for the report to make sure you " & _ "entered the correct criteria (for example, a valid range " & _ "of dates).", vbOKOnly + vbInformation Cancel = TrueSub