Order of events for forms and subforms

Order of events for forms and subforms

Events occur for forms when you open or close a form, move between forms, or work with data on a form.

Opening and closing a form

When you open a form, the following sequence of events occurs for the form:

Open Þ Load Þ Resize Þ Activate Þ Current

If there are no active controls on the form, the GotFocus event also occurs for the form after the Activate event but before the Current event.

When you close a form, the following sequence of events occurs for the form:

Unload Þ Deactivate Þ Close

If there are no active controls on the form, the LostFocus event also occurs for the form after the Unload event but before the Deactivate event.

Moving between forms

When you switch between two open forms, the Deactivate event occurs for the first form, and the Activate event occurs for the second form:

Deactivate (form1) Þ Activate (form2)

The Deactivate event for a form also occurs when you switch from the form to another window in Microsoft Access. However, the Deactivate event doesn't occur when you switch to a dialog box, to a form whose PopUp property is set to Yes, or to a window in another application.

Note   An Open event doesn't occur if you move to a form that is already open, even if you've moved to the form by carrying out an OpenForm action.

Working with data on a form

Form and control events occur as you move between records in the form and change data. For example, when you first open a form, the following sequence of events occurs:

Open (form) Þ Load (form) Þ Resize (form) Þ Activate (form) Þ Current (form) Þ Enter (control) Þ GotFocus (control)

Similarly, when you close a form, the following sequence of events occurs:

Exit (control) Þ LostFocus (control) Þ Unload (form) Þ Deactivate (form) Þ Close (form)

If you've changed data in a control, the BeforeUpdate and AfterUpdate events for both the control and the form occur before the Exit event for the control. For more information on the order of events for controls on forms, click .

Working with subforms

When you open a form containing a subform, the subform and its records are loaded before the main form. Thus, the events for the subform and its controls (such as Open, Current, Enter, and GotFocus) occur before the events for the form. The Activate event doesn't occur for subforms, however, so opening a main form triggers an Activate event only for the main form.

Similarly, when you close a form containing a subform, the subform and its records are unloaded after the form. The Deactivate event doesn't occur for subforms, so closing a main form triggers a Deactivate event only for the main form. The events for the controls, form, and subform occur in the following order:

  1. Events for the subform's controls (such as Exit and LostFocus)

  2. Events for the form's controls (including the subform control)

  3. Events for the form (such as Deactivate and Close)

  4. Events for the subform

For more information on events, click .