Microsoft Office Tutorials and References
In Depth Information
Changing Form Controls with VBA
To change the value (contents) of a control, set the control’s Value
property equal to the value you want to put in that control. Here’s the syntax:
Me. ControlName .Value = desiredValue
The desiredValue part has to be an appropriate data type for the control.
Suppose that a form control named Paid is bound to a Yes/No field in the
underlying table. The following statement makes that control True, thereby
putting a check mark in its check box:
Me.Paid.Value = True
To clear that check mark, use
Me.Paid.Value = False
To insert new text into a text box, use the standard syntax, but enclose the
new text in quotation marks. If the current form has a Text Box control
named Product Name that’s bound to a Text field, the following statement
puts the text in quotation marks in that control:
Me.ProductName.Value = “9-Passenger Lear Jet”
To increase or decrease a value in a numeric field, set the Value property
of its control to an expression that does the appropriate math. Suppose that
a form contains a UnitPrice control that’s a Currency field. The following
statement increases that control’s current value by 10 percent:
Me.UnitPrice.Value = 1.10 * Me.UnitPrice.Value
Examples of controlling properties
Now take a look at how you might use the preceding techniques to control
what happens to controls in the payment-method example shown near the
start of this chapter. Figure 4-4 shows those controls on a form, in Design
view, so that you can see the actual control names. The Label control, named
ExpireLabel, doesn’t show a name, so we point that one out in the figure.
We also select that control — and show its property sheet — so that you
can see its Name property and some of the other properties it offers. The
property sheet for a control is how you find out exactly what properties the
control offers.
 
Search JabSto ::




Custom Search