Understanding Objects, Properties, Events, and Methods
Many people, especially those accustomed to a procedural language, don't understand the concept of objects, properties, methods, and events. As mentioned earlier, you need a thorough knowledge of Access's objects, their properties, the methods associated with them, and the events that each object can respond to if you want to be a productive and successful Access programmer.
What Exactly Are Objects?
Objects are all the things that make up your database. They include tables, queries, forms, reports, data access pages, macros, and modules, as well as the components of those objects. For example, a Table object contains Field and Index objects. A Form object contains various controls (text boxes, combo boxes, list boxes, and so on). Each object in the database has specific properties that determine its appearance or behavior. Each object also has specific methods, which are actions that can be taken upon it.
What Exactly Are Properties?
A property is an attribute of an object, and each object has many properties. Often, different types of objects share the same properties; at other times, an object's properties are specific to that particular object. Forms, combo boxes, and text boxes all have Width properties, for example, but a form has a RecordSource property that the combo box and text box don't have.You can set most properties at design time and modify them at runtime; however, you can't modify some properties at runtime, and you can't access others at design time (you can only modify them at runtime). Access's built-in Help for each property tells you one of the following:
- You can set this property in the object's property sheet, a macro, or Visual Basic.
- You can set this property only in Design view.
- You can access this property by using Visual Basic or a macro.
Each of these descriptions indicates when you can modify the property.As a developer, you set the values of many objects' properties at design time; the ones you set at design time are the starting values at runtime. Much of the VBA code you write modifies the values of these properties at runtime in response to different situations. For example, suppose that a text box has a Visible property. Let's take a look at an example. If a client is paying for something by cash, you might not want the text box for the credit card number to be visible. If he's paying by credit card, you might want to set the Visible property of the text box with the credit card number to True. This is just one of the many things you can do to modify the value of an object's property at runtime in response to an event or action that has occurred.You might wonder how you can determine all the properties associated with a particular object (both those that can be modified at design time and those that can be modified at runtime). Of course, to view the properties that can be set at design time, you can select the object and then view its property sheet. Viewing all the properties associated with an object is actually quite easy to do; just invoke Help by pressing F1. Type properties of combo boxes into the Search text box and click the Start Searching button. In Figure 8.1, properties of combo boxes has been typed into the text box and Start Searching button has been clicked. Notice that one of the entries in the list box at the top of the Search Results window is properties of list boxes, combo boxes, drop-down list boxes, and Lookup fields. If you click the link, a window opens providing you with two options (see Figure 8.2). To find out about properties of list and combo boxes on a form, click the first link. Figure 8.3 shows help information on the properties you can use to create or modify list boxes and combo boxes on a form. You can also use the Object Browser to quickly and easily view all properties associated with an object.
Figure 8.1. The Search Results task pane.

Figure 8.2. Information about the combo box control.

Figure 8.3. Help associated with a combo box.

What Exactly Are Events?
Windows is an event-driven operating system; in other words, the operating system responds to many events that are triggered by actions that the user takes and by the operating system itself. Access exposes many of these events through its Object Model. An event in an Access application is something your application can respond to. Events include mouse movements, changes to data, a form opening, a record being added, and much more. Users initiate events, as does your application code. It's up to you to determine what happens in response to the events that are occurring. You respond to events by using macros or VBA code. Each Access object responds to different events. If you want to find out all the events associated with a particular object, take the following steps:
Figure 8.4. The list of events associated with a text box.

What Exactly Are Methods?
Methods are actions that an object takes on itself. As with properties and events, different objects have different methods associated with them. A method is like a function or subroutine, except that it's specific to the object it applies to. For example, a form has a GoToPage method that doesn't apply to a text box or most other objects.