Modules: What they are and how they work

Modules: What they are and how they work

What is a module?

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

Parts of a module

There are two basic types of modules: class modules and standard modules. Each procedure in a module can be a Function procedure or a Sub procedure.

Class 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 the mouse on 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. To see the module for a form or report, click Code on the toolbar in form or report Design view.

Choose an object and an event to select a procedure

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

In Access 95, class modules exist in association only with a form or report. 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 Modules under Objects on the Database window. You can use a class module in Modules to create a definition for a custom object. To find out more about programming with these class modules, click .

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

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

You can view the list of standard modules in your database by clicking Modules under Objects in the Database window. Form, report, and standard modules are also listed in the Object Browser.

For more information on procedures, click .