Creating Class Modules

Up to this point, you have used the basic data types and a few other classes that are part of Access and VBA (Visual Basic for Applications), but it is also possible to create your own data types using VBA, called a class. A class is a means of encapsulating related functions and data. Creating a user-defined class is very useful, because it allows users to create their own data types for specific tasks. For example, someone might create an Error class to provide functionality related to dealing with errors for the application. Think about all of the Access objects you have used so far throughout this book; those are all classes too. In fact, most modern-day programming languages provide some sort of method for creating user-defined types. Regardless of the application, you are sure to create plenty of class modules when building VBA code in Access.


This lesson is designed to provide in-depth information about creating user-defined classes in VBA. You should be familiar with Access databases, creating modules, and basic VBA programming. Otherwise, this lesson does not require any other specific knowledge of Access.


The easiest method for creating a new user-defined VBA class in Access is to create a new class module in the database. To create a class module using Access 2010, complete the following steps:

  1. Open the database that you want to create the class in using Access 2010.
  2. On the Create Ribbon, click the Class ...

Get Microsoft® Access® 2010 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.