NoData Event — Event Procedures

Description

To create an event procedure that runs when the NoData event occurs, set the OnNoData property to [Event Procedure], and click the Build button.

Syntax

Private Sub Report_NoData(Cancel As Integer)

The NoData event procedure has the following argument.

Argument

Description

Cancel

The setting determines whether to print the report. Setting the Cancel argument to True (–1) prevents the report from printing. You can also use the CancelEvent method of the DoCmd object to cancel printing the report.


See Also   NoData event — macros.

Example

The following example shows how to cancel printing a report when it has no data. A message box notifying the user that the printing has been canceled is also displayed.

To try this example, add the following event procedure to a report. Try running the report when it contains no data.

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 = True
End Sub