Passing Arguments Using OpenArgs
You learned how to pass values to a procedure using arguments. In a similar way, you can pass values to a report, but outside of the normal procedure structure, using the OpenArgs argument and property.
The OpenArgs argument belongs to the OpenReport method, and handles the actual passing of the value to the report. The property belongs to the report itself and receives and stores the passed value.
You can learn how to use the OpenArgs method and property in forms by reviewing "Passing Arguments Using OpenArgs page 151.
Let's suppose you don't always need to see all the detail records in the billing report; you want just a summary instead. Using the OpenArgs method, you can pass a value to the report that hides the detail records when you want. To add this functionality to TimeTrack, do the following:
Open the BillingReportSetup form in Design view and add a check box just below the Open Report command button. (Note that this example is working with the original report opening button and not the Advanced Report button that you added in Chapter 13.) Name the new control chkSummary. Set the caption of the check box to Summary.
Set the new control's Default Value property to 1 so it's selected by default.
Modify the cmdOpenReport_Click() event procedure by adding the OpenArgs argument to the OpenReport method, as follows:
DoCmd.OpenReport "BillingReport", acViewPreview, , , , chkSummary
The OpenArgs argument passes chkSummary's value (checked or unchecked) to the report's OpenArgs property.
Save and close the form.
Add the following line to the BillingReport report's Open event, immediately following the DoCmd.Maximize statement:
Reports("BillingReport").Section(acDetail).Visible = Me.OpenArgs
Save and close the report.
Return to the modified form. Select Bill's Auto Glass and enter 10/1/04 and 10/31/04.
Next, uncheck the new check box control as shown in Figure 14.1. Then, click the Open Report button. Figure 14.2 displays the summarized values without the detail records. Close the report and the form when you're done.
Figure 14.1. Add a check box to the setup form.
Figure 14.2. Use the OpenArgs method to toggle between a detailed and a summarized report.
Opening the report with the check box checked passes the value 1 or True, which is the section's default setting. That's why you made checked the default. Unchecked, the OpenArgs argument passes 0, or False. When this is the case, the Visible property is set to False and the Detail section is hidden in the previewed report.