VBA is an object-oriented programming (OOP) language. OOP is a type of programming in which programmers define a complete data structure, from data types to the operations that can be applied to the data structure. Programmers can create an entire object that contains both data and the operations that the object can perform. Programmers can also create relationships between objects.

There are a lot of objects you can access in VBA. The collection of objects exposed by a particular application is called an object library. There are many different object libraries you can access in VBA. For example, you can use VBA to manipulate the Access object library and work with objects such as tables, queries, forms, and reports. You can set references (which we'll cover in the next chapter) to other object libraries such as Microsoft Outlook, Adobe Acrobat, or Microsoft Word. Every time you set a reference to another application's object library, you have access to all of the objects within that library. An object is generally thought of as a physical thing. Let's say you're setting a reference to a car's object library. Once you set the reference to the object library for the car, you can access all of the car's objects, such as its tires, roof, carpet, steering wheel, and windows.


A property is a physical attribute of an object. Each property can have multiple values. For example, the properties for a car object include color (silver), doors (four), and cylinders (four). However, the car has objects of its own. The car's tire object has a brand property of Michelin. The car's carpet object has properties of style (plush) and clean (true). Some properties of an object can be easily changed. If you want to change the color of the car, all you need to do is find an auto detailer and choose another color. In as short as one day, the carpet's clean property can easily turn to false. However, you can't easily change the number of doors on the car (well, you could just take them off, but then you wouldn't have a complete car anymore). Short of completely replacing the engine, you can't change the number of cylinders. Objects in VBA have the same type of properties. Some can be changed and some cannot.

Every object in Access has properties as well. The form object, for example, has many properties including Border Style, Width, Height, and Caption. Each of these properties has many possible values. The Border Style property can be set to None, Thin, Sizable, and Dialog. Each choice presents the form object with a slightly different look. Before you start manipulating properties in VBA code, take a look at the object and examine some of its properties. In the case of a form, launch the form in design mode and change some of its properties. Then run the form and see how the properties you changed affect the display of the form.

Was this article helpful?

0 0

Post a comment