Share this Page URL

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

Presenting Data with Reports 373 12. For the report's Open event procedure, enter the following code between the Sub and End Sub statements that Access provides: On Error GoTo Report_Err DoCmd.OpenForm "ExpenseReports", , , , , acDialog Select Case Forms!ExpenseReports!optExpenseReport.Value Case Is = 1 Me.GroupHeader1.Visible = False Me.GroupFooter1.Visible = False Me.GroupFooter0.Visible = False Me.GroupHeader1.Height = 0 Case Is = 2 Me.Detail.Visible = False Me.Detail.Height = 0 Me.lblCategoryTotal.Visible = False Me.lblDatePurchased.Visible = False Case Is = 3 Me.txtExpenseType.Visible = False End Select Report_Exit: Exit Sub Report_Err: Cancel = True Resume Report_Exit This procedure sets the Visible property for various report sections to False depending on which selection a user makes in the ExpenseReports form. If Detail (option 1) is selected, the code hides the sections that display summary data (ExpenseType Header, ExpenseType Footer, and CampaignID Footer). It also sets the Height property of the ExpenseType Header section to 0 to remove white space from the report. If a user selects option 2, to view summary data, the code hides the Detail section, sets the section's height to 0, and also hides labels that relate to detailed data. Finally, if a user selects the third option, to view both detailed and summary data, the code sets the Visible property of the text box that displays the expense type in the Detail section to False, which hides redundant labeling of data.