I use the techniques covered in this section in many of the applications that I distribute to my users. The report that we'll build could be included in our hypothetical time and billing application. It covers generic techniques that you can use in any application that you build.
One report not covered in the chapter is the rptEmployeeBillingsByProject report. This report has the following code in its NoData event:
Private Sub Report_NoData(Cancel As Integer) 'If no data in the RecordSource underlying the report, 'display a message and cancel printing MsgBox "There is no data for this report. Canceling report..." Cancel = True End Sub
If there's no data in the report's RecordSource, a message box is displayed, and the report is canceled. The Open event of the report looks like this:
Private Sub Report_Open(Cancel As Integer) 'Open the criteria form DoCmd.OpenForm "frmReportDateRange", _ WindowMode:=acDialog, _ OpenArgs:="Employee Billings by Project" 'If the criteria form is not loaded, cancel printing If Not IsLoaded("frmReportDateRange") Then Cancel = True End If End Sub
The report's Open event opens a form called frmReportDateRange (see Figure 10.21). This form is required because it supplies criteria to the query underlying the report. If the form isn't loaded successfully, the report is canceled.
Finally, the report's Close event looks like this:
Private Sub Report_Close() 'Close the criteria form when the report closes DoCmd.Close acForm, "frmReportDateRange" End Sub
The report cleans up after itself by closing the criteria form.