Microsoft Office Tutorials and References
In Depth Information
Changing Form Controls with VBA
Save : One of the following constants:
• acSaveNo: Closes the object without saving any changes
• acSavePrompt: (Default) Displays the standard Do you want to
save... message so the user can choose whether to save
• acSaveYes: Saves all changes to the form and then closes it
If you want to close a form from code and save the user’s changes without
prompting, use the following syntax:
DoCmd.Close acForm, formName , acSaveYes
formName is the name of the form that you want to close. If you want a line
of code to close a form named Products Form, the syntax is
DoCmd.Close acForm, “Products Form”, acSaveYes
Changing Form Controls with VBA
When a form is open, you can use VBA code to change the contents and
even the appearance of the form, from the big picture down to the individual
controls. Suppose that you have a form that includes a control for choosing
a payment method. When the user chooses a payment method, you want to
enable or disable other controls on the form based on the selected payment
method. Alternatively, you may want to autofill some other controls on the
form or even make some controls visible or invisible, depending on which
payment method the user selected.
Figure 4-3 shows a few examples. When the user selects Cash, the Paid
field is marked True, and all other fields are disabled. When the user selects
Credit Card, the fields for entering credit card information are enabled.
When the user selects Purchase Order, the P.O. Number control is
enabled, and the Paid check box is cleared.
Figure 4-3:
with VBA.
Search JabSto ::

Custom Search