ACC2: Comparison of Form or Report Modules and Global Modules

Last reviewed: April 2, 1997
Article ID: Q114217
The information in this article applies to:
  • Microsoft Access version 2.0

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

In Microsoft Access version 1.x, you can extend the behavior of forms, reports, and controls by writing a function or macro, and then calling that code when an event occurs.

In Microsoft Access version 2.0, you can still call macros or functions directly from events. In addition, you can write event procedures that are stored in special modules, called form or report modules, for each form or report. This functionality is similar to how Microsoft Visual Basic stores procedures for forms.

MORE INFORMATION

Comparison of Global Modules and Form and Report Modules

There are several differences between code in a global module and code in a form or report module, including the following:

  • Identifiers in form and report modules are private to the module's form or report. This lets you write less code to accomplish the same task. For example, you can use "Me.ControlName.Enable = True" instead of "Forms!FormName!ControlName.Enable=True."
  • Procedures in form and report modules cannot be called from outside the module's form or report. These procedures can only be called from the form or report itself, expressions on the form or report, or other code in the form or report module.
  • A form or report module is stored with its form or report, and moves with it when you perform such operations as copy, paste, import, or export.
  • Deleting a form or report object deletes its associated form or report module.
  • A form or report module is only loaded into memory when its associated form or report is opened, and is discarded when its form or report is closed.

    Note that this affects the behavior of the Compile All, Find, and Replace commands. For example, to globally replace an item in all modules in your database, you must first open all forms and reports with form or report modules. If you do not open the forms and reports first, only the contents of global modules will be affected.

  • When an error occurs in code in a global module, the module will open and the error will be selected for you. When an error occurs in code in a form or report module, you are only notified of which event caused the error. The form or report module will not open.
  • Form and report modules are not listed in the Database window.

How to View Code in a Form or Report Module

Method 1:

  1. Open the form or report in Design view.

  2. From the View menu, choose Code. Or, choose the Code button on the toolbar.

Method 2:

  1. Open the form or report in Design view. This loads the form or report's module into memory.

  2. From the Window menu, choose Database.

  3. In the Database window, choose the Module button.

  4. Open any module.

  5. Press F2. The form or report module will be listed as Object.ObjectName (for example, Form.FormName).

REFERENCES

For more information about form and report events, search for "events: forms" or "events: reports," and then "Events and Event Properties Reference" using the Microsoft Access Help menu.


Additional query words: code behind forms cbf
Keywords : FmsHowto kbusage
Version : 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.