Set the value of a property in response to an event

Microsoft Office Access 2003

  1. To create a macro, click Macros Button image under Objects, and then click the New button on the Database window toolbar.
  2. In a blank action row, click SetValue in the action list.
  3. Set the Item argument to the identifier for the property whose value you want to set, and then set the Expression argument to the value you want to assign to the property.
  4. Click Save Button image to save the macro.
  5. Go to the form or report, open the property sheet for the object whose event will run the macro, and set the event property to the name of the macro.

ShowUse Visual Basic code

  1. To open the event procedure for the appropriate event, open the form in Design view.
  2. Display the property sheet for the form and then click the Event tab.
  3. Click the event property for the event that you want to trigger the procedure.

    For example, to respond to a mouse click on a command button, open the button's OnClick event procedure.

  4. Click Build Button image next to the property box to display the Choose Builder dialog box.
  5. Double-click Code Builder to display the event procedure window
  6. Add an assignment statement to the procedure by typing the identifier for the property whose value you want to set, an equal sign (=), and the value you want to assign.
  7. Do one of the following:

    To refer to the property of a control on the current form, type the Me keyword followed by the ! operator, the name of the control, the . (dot) operator, and the name of the property. For example, the following statement assigns the value False to the Visible property of the DateDue control on the current form:

    Me![DateDue].Visible = False
    						

    To refer to the property of a control on a different form, type the control's full identifier. For example, the following identifier refers to the Visible property of the DateDue control on the ShipForm form:

    Forms![ShipForm]![DateDue].Visible