Finding class modules

Like standard modules, class modules contain VBA code that tells Access what to do. Unlike standard modules, however, you won't find any class modules in the database window. Class modules are hidden behind forms and reports in your database.

It might help to define the term class as a class of objects. In Access, tables are one class of objects, queries are another class, forms are another class, reports are another, and so forth. Or looking at it from the other direction, a single form is an object within your database. That single form is also a member of the class of objects known as forms.

Class modules are not global nor public like standard modules. To the contrary, class modules are very private beasts. They bring new meaning to the concept of hermit. Not only are class modules invisible to you most of the time, but they're always invisible to each other. The VBA code in a class module is visible (and usable) only to the form or report to which the class module is attached.

I think that it helps to envision a class module as literally being hidden behind its form, as in Figure 1-4. The VBA code in the class module is always hidden from the other objects in the database. The class module might be hidden from you as well if you don't know how to find it.

Figure 1-4:

Class modules hide behind forms and reports.

Figure 1-4:

Class modules hide behind forms and reports.

-Class module behind form

-Form

-Class module behind form

-Form

You have several ways to get to a form or report's class module, as you'll discover in upcoming chapters. For now, if you just want to open a class module and have a look, here's one way to do it:

1. In the database window, click Forms or click Reports, depending on which type of object you want to open.

2. Right-click the name of any form or report and choose Design View.

To see the class module for the open form or report, click the Code button on the toolbar or choose ViewOCode from the Access menu bar (see Figure 1-5).

Figure 1-5:

Class modules are accessible from form and reports Design views.

Figure 1-5:

Class modules are accessible from form and reports Design views.

Form open in Design view
0 0

Post a comment