Common Report Events

Here are some events on reports that are commonly used. These events can run code to customize and display reports so that they are much more flexible for your users.

□ Report—On Open: This fires before the recordset is evaluated for the report. Just as with forms, you can use this event to change the recordset (by changing the Where or Order By clause) before the report continues to load. This can be especially useful when you use a form to prompt the user for selection criteria before the report continues to load. This technique is described in detail in Chapter 14. This event can be cancelled by setting the Cancel parameter to True, which will prevent the report from continuing to open.

□ Report—On Activate: This event fires after the On Open event, and just as the report window is displayed to the user. The main thing this event is used for is to maximize the Access windows using DoCmd.Maximize. This allows the user to see more of the report. However, you'll probably want to restore the Access windows to their previous sizes when the report closes, which brings us to the On Close event.

□ Report—On Close: As you might guess, this event fires when the report closes. A common line of code to include here is DoCmd.Restore to restore the sizes of your form windows that were maximized in the On Activate event.

□ Report—On No Data: The On No Data event fires after the On Open event when the report evaluates the recordset and discovers that there are no records. This can easily happen if you allow your user to specify the criteria for the report and they choose a combination of values that doesn't exist in the database. In the On No Data event, you can display a message box to the user, then set the Cancel parameter to True, which will close the report.

0 0

Post a comment