Show All

Validate data by using a macro

  1. To create a macro, click Macros under Objects.
  2. Click the New button on the Database window toolbar.
  3. Add an action to the macro.

    How?

    1. In the Macro window, click the first empty row in the Action column. If you want to insert an action between two action rows, click the selector for the action row just below the row where you want to insert the new action, and then click Insert Row on the toolbar.
    2. In the Action column, click the arrow to display the action list.
    3. Click the action you want to use.
    4. In the lower part of the window, specify arguments for the action, if any are required. For action arguments whose settings are a database object name, you can set the argument by dragging the object from the Database window to the action's Object Name argument box.
    5. Type a comment for the action. Comments are optional.
  4. In the Macro window, make sure Conditions on the toolbar is pressed in.
  5. In the Condition column of a blank action row, enter a validation condition.
  6. In the Action column, click the action in the action list that you want to carry out if the validation condition is true.
  7. For any additional actions you want to carry out if the validation condition is true, enter an ellipsis (...) in the Condition column followed by the action in the Action column. For example, it's usually a good idea to carry out a CancelEvent action for each validation condition after any other actions have been carried out.
  8. Click Save to save the macro.
  9. Open the form in Design view.
  10. For the event that you want to trigger the validation, set the event property to the name of the macro. For example, to trigger the validation when a control is updated with changed data, set the BeforeUpdate event property of the control to the name of the macro.

    Note   To validate data before a record as a whole is updated, attach the validation macro to the form's BeforeUpdate event rather than to the control's BeforeUpdate event.