Changing the Value of a property

To change the value of a property, follow the property name with an equal sign and a valid value for the property. For example, the Visible property of a control can be True (Yes) or False (No). For example, the following statement makes invisible a control named myButton by setting its Visible property to False (No):

Forms!myForm!myButton.Visible = False

To make that same control visible again from VBA, set its Visible property back to True (Yes), as follows:

Forms!myForm!myButton.Visible = True

To refer to specific objects in a database, VBA uses the same identifier syntax used in Access expressions. An identifier can use two different characters as delimiters (separators) between words: either an exclamation point (!) or a period (.). Programmer lingo for these characters is bang and dot, respectively. The rules for using them are as follows:

i! (bang): Use the bang character to precede any name you made up yourself, such as the name of a form you created or the name of a control you created on the form.

i. (dot): Use a dot to precede a property name or any "official" name that you didn't make up yourself.

For example, in Forms!myForm!myButton. Visible, both myForm and myButton are names that I made up. I did so while creating those objects in Access. Those two names are both preceded by a bang (!) character because they're both names I made up.

The final name in the identifier, Visible, is a reference to the object's Visible property. I didn't make up the name Visible myself: Rather, that's Access's name for the property, as you can see in the Properties sheet in Figure 5-6. Because Visible is an "official" property name, its name is preceded with a dot (.) rather than a bang (! ).

For more information on identifiers, your best bet is to consult an Access book (as opposed to an Access VBA book, like this one). Or you can just search Access's Help (not VBA's Help) for identifier.

0 0

Post a comment