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:
- Open the form or report in Design view.
- From the View menu, choose Code. Or, choose the Code button on
the toolbar.
Method 2:
- Open the form or report in Design view. This loads the form
or report's module into memory.
- From the Window menu, choose Database.
- In the Database window, choose the Module button.
- Open any module.
- 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.
|