What Is a Property

Properties are characteristics of an object that determine its behavior or appearance. Examples of properties include the name, caption, or size of a control. Figure 3.1 shows various properties of a Form. This dialog box can be displayed when the Form is in design view and you select View C> Properties or choose Alt+Enter. Note that some of the properties listed in the figure have selectable Yes/No values, some are text input fields like the Caption property, and others have different choices you can select from a drop-down list.

Form Ö

Form v

Format Data Event Other All

Record Source

Filter

Order By

Allow Filters

Caption

Default View

Allow Form View

Allow Datasheet View

Allow PivotTable View

Allow PivotChart View

Allow Edits

Ch 3 Test ForrrJ

Sinole Form

Yes

Figure 3.1

After setting the preceding Caption property for this particular form and running the form, notice how the caption of the form (shown in Figure 3.2) is now set to the value that was in the Properties dialog box.

Hi Ch 3 Test Form ^EJQ

A

Name:

-

Record: M J j l H . of 1

< >

Figure 3.2

You can also select other objects on the form in the object drop-down list of the Properties Window, such as text box controls or labels, as shown in Figure 3.3.

As shown earlier, by selecting another object from the list in the Properties dialog box, you can view and modify its respective properties. Various objects share many of the same properties. For example, forms, text boxes, and labels all have a Caption property, as well as a Name property.

The Properties Window can be used to view and modify properties as well as events. This concept will be discussed later in the chapter.

^T Form @

Form v

Detail corm

■blNams

-

D IS

Allow Filters

Default View

Allow Form View

Allow Datasheet View

Allow PivotTable View

Alio1,1 PivotChart Wei

Ch 3 Test Form

Sinaie Form

Yes

Allow Edits Yes

Figure 3.3

Figure 3.3

The property values that are set in the Properties dialog box, such as the Caption property shown previously, are called design time settings. Design time settings are those you specify at design time that become the starting value for that object. The starting value can be modified at runtime in your VBA code, or at a later time in design view. For example, to change the Caption property of the preceding form at runtime while the program executes, you could use the following VBA command:

Forms.Item("frmTestProperties").Caption = "New caption goes here."

In addition to the Properties dialog box, another way to see the available properties for an object is by typing VBA code in the Visual Basic Editor. Figure 3.4 shows that as you type the name of an existing object and hit the period key, the list of properties available for that object are displayed.

This feature is very helpful because it keeps you from having to memorize the exact syntax of every property. You just look up a property as you write your code.

The values in the list on Figure 3.4 are all properties, as is indicated by the icon showing a hand holding a card:

Other items can be present in the drop-down list as well, as I discuss later in this chapter. For now, be aware that you can see a list of properties available for an object within the code window in the Visual Basic Editor (VBE).

Some objects are visual—such as forms, text boxes, labels, and reports. Other objects are not visual. The user sees nothing when those objects are used. An example of a nonvisual object is a recordset that holds data from a database. Although you may later display data from the recordset on a form, the object itself does not have a visual presence. Both visual and nonvisual objects can have properties.

Yet another way to view the properties available for an object is by using the Object Browser, discussed later in this chapter.

Figure 3.4
0 0

Post a comment