About modules

Microsoft Office Access 2003

A module is a collection of Visual Basic declarations and procedures that are stored together as a unit.

Parts of a module

Callout 1 Object box

Callout 2 Procedure box

Callout 3 Declarations

Callout 4 Procedures

Callout 5 Procedure View button

Callout 6 Full Module View button

ShowClass modules

Form and report modules are class modules that are associated with a particular form or report. Form and report modules often contain event procedures that run in response to an event on the form or report. You can use event procedures to control the behavior of your forms and reports, and their response to user actions, such as clicking a command button.

When you create the first event procedure for a form or report, Microsoft Access automatically creates an associated form or report module.

Choose an object and an event to select a procedure

Callout 1 To view or add a form procedure, choose one of the form's objects from the Object box ...

Callout 2 ... and then choose an event from the Procedure box. Names of events that already have procedures are bold.

Procedures in your form and report modules can call procedures you have added to standard modules.

In Access 97 or later, class modules can also exist independent of a form or report, and this type of class module is listed in the Database window. You can use a class module to create a definition for a custom object. In Access 95, class modules exist in association only with a form or report.

ShowStandard modules

Standard modules contain general procedures that aren't associated with any other object, and frequently used procedures that can be run from anywhere within your database. The major difference between a standard module and a class module that is not associated with a particular object is one of scope and lifetime. The value of any variables or constants that are declared or exist in a class module without an associated object are available for use only while that code is running and only from that object.

Standard modules contain procedures that are available from anywhere in the database

Callout 1 Function name and arguments

Callout 2 Visual Basic declarations and code statements

Standard modules are listed in Modules under Objects in the Database window. Form, report, and standard modules are also listed in the Object Browser.