- Create a macro.
- In a blank action row, click SetValue in the action list.
- Set the Item argument to the identifier for the control whose value you want to set, and then set the Expression argument to the identifier for the control whose value you want to assign to the first control.
These arguments assign the value of the City control to the ShipCity control.
- Click Save to save the macro.
- Run the macro.
Note Depending on the context, you might need to use qualified identifiers for the controls. For example, instead of [ShipCity], you might need to use the action argument Forms![ShipForm]![ShipCity].
- Create a Visual Basic procedure.
If you want to set the value of control when a particular event occurs, create an event procedure.
You can set an event property for a form, report, or control to [Event Procedure] to run code in response to an event. Microsoft Access creates the event procedure template for you. You can then add the code you want to run in response to the particular event.
- Open a form or report in Design view.
- Display the property sheet for the form or report, or for a section or control on the form or report.
- Click the Event tab.
- Click the event property for the event that you want to trigger the procedure. For example, to display the event procedure for the Change event, click the OnChange property.
- Click Build next to the property box to display the Choose Builder dialog box.
- Double-click Code Builder to display the event procedure Sub and End Sub statements in the form module or report module. These statements define, or declare, the event procedure.
Microsoft Access automatically declares event procedures for each object and event in a form or report module by using the Private keyword to indicate that the procedure can be accessed only by other procedures in that module.
- Add the code to the event procedure that you want to run when the event occurs. For example, to produce a sound through the computer's speaker when data in the CompanyName text box changes, add a Beep statement to the CompanyName_Change event procedure, as follows:
Private Sub CompanyName_Change() Beep End Sub
The event procedure runs each time the Change event occurs for the object.
- Add an assignment statement to the procedure by typing the identifier for the control whose value you want to set, an equal sign (=), and the identifier for the control whose value you want to assign to the first control.
To refer to the value of a control on the current form, type the Me keyword followed by the ! operator and the name of the control. For example, the following statement assigns the value of the City control on the current form to the ShipCity control on the current form:
Me![ShipCity] = Me![City]
To refer to the value of a control on a different form, type the control's full identifier. For example, the following identifier refers to the ShipCity control on the ShipForm form:
Forms![ShipForm]![ShipCity]
- Run the procedure.