Passing Arguments Using OpenArgs

 < Day Day Up > 

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:

  1. 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.

  2. Set the new control's Default Value property to 1 so it's selected by default.

  3. 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.

  4. Save and close the form.

  5. Add the following line to the BillingReport report's Open event, immediately following the DoCmd.Maximize statement:

     

     Reports("BillingReport").Section(acDetail).Visible = Me.OpenArgs 

  6. Save and close the report.

  7. Return to the modified form. Select Bill's Auto Glass and enter 10/1/04 and 10/31/04.

  8. 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.

    graphics/14fig01.jpg


    Figure 14.2. Use the OpenArgs method to toggle between a detailed and a summarized report.

    graphics/14fig02.jpg


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.

     < Day Day Up > 


    Automating Microsoft Access with VBA
    Automating Microsoft Access with VBA
    ISBN: 0789732440
    EAN: 2147483647
    Year: 2003
    Pages: 186

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net