Introducing the Report Module and Events

 < Day Day Up > 

For the most part, VBA code is stored in one of two module types: standard or object. The object module is a special module attached to a report or a form. The module is saved with the object and supports events and properties that are unique to the object.

Most of the code you enter and store in a report module (or a form module for that matter) comes in the form of event procedures code that's executed when some action occurs. For instance, code added to the report's Open event is executed when you open the report. Let's look at a quick example that maximizes the report:

  1. Select the BillingReport report in the Database window and then click the Code button in the Database toolbar. This launches the VBE with the BillingReport report's module current.

  2. Enter the following code:


     Private Sub Report_Open(Cancel As Integer)  DoCmd.Maximize End Sub 

  3. Click the Save button.

  4. Return to the Access Database window and close the report.

  5. Open the BillingReportSetup form. Remember, this form launches the BillingReport report after you specify a few values that limit the records that make it to the report.

  6. Choose Bill's Auto Glass and enter the dates 10/1/04 and 10/31/04.

  7. Click the Open Report button, which triggers the report's Open event and maximizes the report window in Print Preview.

Read about report events and their sequence in "The Event Sequence for Reports on page 170.

     < Day Day Up > 

    Automating Microsoft Access with VBA
    Automating Microsoft Access with VBA
    ISBN: 0789732440
    EAN: 2147483647
    Year: 2003
    Pages: 186 © 2008-2017.
    If you may any questions please contact us: