12.3. Creating a Class Module

We learn best by doing, so to learn the basic techniques used to create a class module, this section is devoted to creating one you may find useful in your own projects.

12.3.1. Adding a Class Module to the Project

To add a new class module to your project, press Alt+F11 from the database window to open a new standard module. Then from the Visual Basic Designer window, select Class Module from the Insert menu. You can also right-click anywhere in the Project Explorer and select Insert|Class Module from the context menu.

VBA opens a new class module and adds a reference to it in the Project Explorer. Copy the clsKennel code into the module, as shown in Figure 12-3. That's it! You've created your first class module!

Figure 12.3. Figure 12-2

12.3.2. A Brief Word on Naming the Class

All things have names, and class modules are no different. The name you give a class module, however, is the name that is shown in both the Project Explorer and the Object Browser, so it should be something relevant and meaningful. For a more in-depth discussion on naming objects, refer to section on Naming Objects, later in this chapter.

To name your class, display the Properties window by selecting it from the View menu, or by pressing F4. Then enter a name in the (Name) property. You might like to review Appendix G for object-naming conventions and prefixes.

You will ...

Get Access 2003 VBA Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.