Objects in VBA


Let’s take the following line segment of code:

DoCmd.GoToRecord … 

DoCmd is an object. As a matter of fact (recall from Chapter 7), you can look up all its particulars by pressing F2 to open the Object Browser:

click to expand

Each component in your project can be represented by an object and accessed programmatically. This includes the tables, forms, reports, and so on. However, as you will see, there are hundreds of objects that are not as obvious to the Access user and will only be used within the VBA environment.

The previous code segment is an object call. In essence, you are sending a message to the object, asking it to do its job. However, what job do you want it to do?

After you make the call to the object, you type a dot (or period). As soon as you do, Auto List Members opens, giving you a list of properties and methods available.

All objects have two basic components: properties and methods. (Remember, the words “property,” “field,” and “attribute” are more or less interchangeable when speaking about objects.) Properties dictate what an object “knows.” As an example, let’s say you have an object called Car. The attributes might be things like its model, color, number of miles, and so on. Methods are what the object can do with the information located in the attributes. For instance, the car can move, go in reverse, stop, and so on.

From here on, we will be examining all objects in this light.




Access VBA Programming
Microsoft Access VBA Programming for the Absolute Beginner
ISBN: 1598633937
EAN: 2147483647
Year: 2006
Pages: 214
Authors: Michael Vine

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net