• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 28. Responding to Events with VB... > Understanding the Role of Class Modu...

Understanding the Role of Class Modules

Class modules, which were introduced by Visual Basic 4.0, are containers for VBA code that relate to a particular class of objects. Access 97 defines two classes (collections)—Forms and Reports—that contain VBA code for a particular instance of the class: a Form or Report object, respectively. In object-oriented programming terms, class modules encapsulate VBA code within a Form or Report object. Code encapsulation lets you create reusable objects. For example, when you copy a form from one Access database to another, the copy you make includes the code in the form's class module.

Access's Form and Report class modules differ from conventional modules in that a Form or Report object is integral to the code and contributes the object's properties (appearance). Conventional modules, such as Northwind.mdb's Utility Functions, appear in the Modules page of the Database window. Your event-handling code creates a custom set of methods (behavior) that are applicable to the object. When you open a form or report, you create the default instance of the corresponding Form or Report object. The default instance of the object appears in the Forms or Reports page of the Database window. VBA 5.0 also lets you create additional temporary, nondefault instances of Form and Report objects with the New reserved word. You need not add an explicit reference to the associated form or report in your code, although in certain expressions you use the Me self-reference to specify the current instance of the Form or Report object.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint