Set Properties by Using Macros
See Also
From a macro, you can set properties for Form, Report, and Control objects, as well as form and report sections. You use the SetValue action from a macro to set the value of a property.
You can't use a macro to set properties of other Microsoft Access objects or ActiveX Data Objects (ADO), or to set the default properties of a control, but you can set them either by using Visual Basic or an object's property sheet in Design view.
To set a form, report, or control property by using a macro
- In a macro, add a SetValue action.
- Set the Item action argument of the SetValue action to an expression that refers to the property you want to set:
Tip If the macro containing the SetValue action runs from the form or report with the property you want to set, you can refer to the property by using just the syntax propertyname. However, it's a good idea to use the full syntax to refer to the property to avoid conflicts with names of controls or Visual Basic keywords. For example, Name is a Microsoft Access property; if you also have a control on your form called Name, you should use the full syntax to refer to both the control and the property.
- Set the Expression action argument of the SetValue action to the value you want to set the property to. If the setting is a string, be sure to enclose it in double (") quotation marks. For example, to set the Caption property of a form to Orders, you would enter "Orders" in the Expression argument.
To set a section property by using a macro
- In a macro, add a SetValue action.
- In the Item action argument, use the syntax Forms!formname.Section(constant).propertyname to refer to the property you want to set. The constant argument refers to a particular section on the form or report, as described in the Section property. For example, the following expression refers to the Visible property of the page header section of the Customers form:
Forms!Customers.Section(acPageHeader).Visible
- Set the Expression action argument as described above.
Note For each property you want to set, you can look up the property in the Help index to find information about:
- Whether you can set the property from a macro.
- Views in which you can set the property. Not all properties can be set in all views. For example, you can set a form's BorderStyle property only in form Design view.
- Which values you can use to set the property. Some properties require settings that don't correspond to values in the property sheet but to numeric values. You may need to set the property by using the settings you would use in Visual Basic rather than those you would use in the property sheet. For example, if the property settings are selections from a list, you must use the value or numeric equivalent for each selection.