Getting the value of a property

The syntax for referring to an object (or collection) property follows the general syntax: where objectCollectionName is any valid object or collection name, and property is any valid property for that object. The dot (.) is the delimiter that separates the object name from the property name.

For example, all collections have a Count property that contains the number of items in the collection. Remember that the Forms collection is an object that contains all currently open forms in Access. Thus, Forms.Count returns the number of open forms in the database. You could see this for yourself by typing the following in the Immediate window and pressing Enter:

? Forms.Count

As always in the Immediate window, the question mark asks, "What is?" In this case, you're asking the Immediate window, "What is the forms count in this database?" (or, "How many forms are open right now in this database?").

If no forms are open in Access, Forms.Count returns 0 (zero). If you open a form (in form view) in Access and then execute the ? Forms.Count statement again, it returns 1. In other words, the value returned by Forms.Count is equal to the number of forms that are currently open in Access — 0 (zero) if no forms are open, 1 if one form is open, 2 if two forms are open, and so forth.

To re-execute a statement in the Immediate window, just move the cursor back to the end of the statement that you want to execute and then press Enter. To quickly delete text in the Immediate window, drag the mouse pointer through it and press Delete.

Every control on every form has a Visible property that determines whether the control is visible on the form. When Visible equals True (Yes), the control is visible. Conversely, when the Visible property is False (No), the control is not visible.

When creating your own forms, there might be instances when you want a control to be visible to the user as well as instances when you don't want it to be visible. For example, on a form that allows a user to enter payment information for an order, you might want to make controls for entering credit card information visible only when the customer is paying by credit card. If the customer pays by check or cash, you might want to make those same controls invisible so that the user doesn't accidentally choose Cash or Check but then type in credit card information.

The syntax for referring to the Visible property of a control named myButton is myButton.Visible. However, like with Access expressions, getting to a specific object from outside its container requires using an identifier, which provides the complete path to the object. For example, the following line

Forms!myForm!myButton.Visible refers specifically to the Visible property of a control named myButton on a form named myForm. The Forms! part at the beginning refers to the Forms collection, which contains all forms that are currently open in Access. Figure 5-6 illustrates how Forms!myForm!myButton.Visible refers to the Visible property of the myButton control.

Figure 5-6:

Forms! myForm! myButton. Visible from an Access viewpoint.

d my Tri


Forms collection (all open forms)

- MyButton

Command Button: myButton

Format Data Event Other

Caption |My Button

Picture (bitmap)

Picture Type [Embedded

Transparent No

Hyperlink Address j_

Hyperlink Sub Address |_

Visible ives

Display When jAlways

Left 11.0417"

0 0

Post a comment