969
CHAPTER
Object-Oriented
Programming
with VBA
IN THIS CHAPTER
Getting acquainted with
object-oriented programming
Looking at how you can
benefit from object-oriented
programming
Making use of property
procedures
Extending a class by adding
properties and methods
Understanding events
Making use of class events
A
major goal in all modern application development is to produce
robust, reusable code. Microsoft Access 2010 provides a number of
ways to make code more reusable, from simple importing or export-
ing of code modules to building runtime code libraries.
This chapter covers one approach to creating code modules that you can
reuse from any Access database. The code modules we describe in this chap-
ter define new types of objects for your Access applications. These objects
include properties and methods, and you can copy the objects into other
Access applications or add them to Access code libraries.
The objects you create enforce modular, object-based programming. You’ve
likely noticed how Access is based on the concept of objects. Microsoft
defines just about everything in an Access application — forms, controls on
forms, reports, and other visible parts of your programs — as some kind of
object.
In addition, any number of hidden objects (such as table relationships) are
lurking in your program. These objects are one of the ways in which Access
is modular in nature. Each built-in Access object (such as a table, query, or
form) performs some task in the application.
In this chapter, I dive into the important topic of object-oriented program-
ming (OOP) in Access. Here you’ll learn what objects are and how to use
them in your applications. You’ll also find out how to build your own objects
using Access VBA code.
Although this chapter discusses objects such as forms and controls as exam-
ples, the emphasis is on the technology of creating and using custom objects
in your Access applications. You create custom objects in your applications
by adding code to a special class module.