Share this Page URL

Chapter 10. Presenting Data with Reports > Using a Report's Open and Close Even... - Pg. 374

Presenting Data with Reports 374 13. 14. 15. The procedure also includes code to handle errors such as a user closing the ExpenseReports form without making a selection. If an error occurs, the procedure simply cancels the report's Open event. Press Alt+F11 to view the report in Design view. In the Properties dialog box, click on the Event tab, and then click in the On Close event property box. Select Event Procedure, and then click the Build button. For the report's Close event procedure, enter the following Close method. (We've shown the code statements that Access provides for reference.) Private Sub Report_Close() DoCmd.Close acForm, "ExpenseReports" End Sub 16. With this single line of code, when a user closes the CampaignExpenses report, the Expen- seReports form is closed as well. Close the Visual Basic Editor, and then click the View button on the toolbar to display the report in the Preview window. As you can see here, before any report data is displayed, Access opens the ExpenseReports form: