BeforeUpdate, AfterUpdate Events

Applies To

Bound Object Frame Control, Check Box Control, Combo Box Control, List Box Control, Option Button Control, Option Group Control, Text Box Control, Toggle Button Control.

Description

These events occur:

  • BeforeUpdate — before changed data in a control or record is updated.
  • AfterUpdate — after changed data in a control or record is updated.

Notes

  • Changing data in a control using a macro or Visual Basic doesn’t trigger these events for the control. However, if you then move to another record or save the record, the form’s BeforeUpdate and AfterUpdate events do occur.
  • The BeforeUpdate and AfterUpdate events apply only to controls on a form, not controls on a report.
  • These events don’t apply to option buttons, check boxes, or toggle buttons in an option group. They apply only to the option group itself.

Remarks

The BeforeUpdate and AfterUpdate events are triggered when a control or record is updated. Within a record, changed data in each control is updated when the control loses the focus or when the user presses ENTER or TAB. When the focus leaves the record or if the user chooses the Save Record command from the File menu, the entire record is updated, and the data is saved in the database.

When you enter new or changed data in a control on a form and then move to another record or save the record by choosing Save Record from the File menu, the BeforeUpdate and AfterUpdate events for the form occur immediately after the BeforeUpdate and AfterUpdate events for the control. If you moved to a different record, the Exit and LostFocus events for the control then occur, followed by the Current event for the record you moved to, and the Enter and GotFocus events for the first control in this record. To run the BeforeUpdate and AfterUpdate macros or event procedures without running the Exit and LostFocus macros or event procedures, save the record using the Save Record command on the File menu.

BeforeUpdate and AfterUpdate macros and event procedures run only if you change the data in a control. These events don’t occur when a value changes in a calculated control. BeforeUpdate and AfterUpdate macros and event procedures for a form run only if you change the data in a record (the data in one or more controls in the record).

For forms, you can use the BeforeUpdate event to cancel updating of a record before moving to another record.

For bound controls, the OldValue property isn’t set to the updated value until after the AfterUpdate event occurs. Even if the user enters a new value in the control, the OldValue property setting isn’t changed until the data is saved. If you cancel an update, the value of the OldValue property replaces the existing value in the control.

You often use the BeforeUpdate event to validate data, especially when you perform complex validations, such as those that:

  • Involve conditions for more than one value on a form.
  • Display different error messages for different data entered.
  • Can be overridden by the user.
  • Contain references to controls on other forms or contain user-defined functions.

Note To perform simple validations or more complex validations, such as requiring a value in a field or validating more than one control on a form, you can use the ValidationRule property for controls and the ValidationRule and Required properties for fields and records in tables.

See Also

Enter, Exit Events.