Microsoft Office Tutorials and References
In Depth Information
Changing Form Controls with VBA
Within VBA, use the following syntax to change a control’s property:
ControlName PropertyName = Value .
ControlName is the complete name of a control on an open form,
PropertyName is the name of the property that you want to change, and
Value is the new value for the property. A dot separates the control name
from the property name. The complete name means that the name has to
contain both the name of the form and the name of the control. In a class
module, however, you can use the keyword Me to stand for the form name.
The keyword Me means “the form to which this class module is attached.”
Some cool control properties
To make a control invisible, use the following syntax:
Me. ControlName .Visible = False
To make the control visible, use the syntax
Me. ControlName .Visible = True
To disable a control so that it’s dimmed and doesn’t respond to mouse clicks
or keyboard presses, set the control’s Enabled property to a False value:
Me. ControlName .Enabled = False
To set the control back to its normal Enabled status, use this syntax:
Me. ControlName .Enabled = True
Why not just show everything?
In case you’re wondering why we don’t show
all the methods of the DoCmd object — or all
the objects, properties, and methods
available in all the object libraries — the truth of
the matter is that there’d be too many words.
No, we’re not too lazy to type that many words.
Rather, there aren’t enough pages in this entire
book to hold that many words.
The sheer quantity of information makes
remembering every detail of every VBA
statement and object nearly impossible, so it
wouldn’t do much good to print that
information here anyway. Even professional
programmers spend a lot of time looking up the syntax
of keywords and objects in the help system (or
the Object Browser). The sooner you become
fluent in using Visual Basic Editor’s help system
or the Object Browser, or both, the better off
you’ll be. See Chapters 1 and 2 of this minibook
for more information on the Object Browser
and VBA help.