Activate, Deactivate Events — Event Procedures

Description

To create an event procedure that runs when the Activate or Deactivate event occurs, set the OnActivate or OnDeactivate property to [Event Procedure], and click the Build button.

Syntax

Private Sub Form_Activate( )

Private Sub Report_Activate( )

Private Sub Form_Deactivate( )

Private Sub Report_Deactivate( )

Remarks

You can use Activate and Deactivate event procedures to display and hide custom toolbars. If you use a Deactivate event procedure to hide a custom toolbar on a form, also make sure to hide the toolbar in response to the Unload event for the form, because the Deactivate event doesn't occur when a form is unloaded. Don't use the GotFocus or LostFocus event to display or hide a toolbar on a form, because these events aren't triggered on forms that contain enabled controls.

You can't cancel the Activate or Deactivate event.

See Also

Activate, Deactivate events — macros.

Example

The following example shows how to display a custom toolbar named CustomToolbar when a form receives the focus and to hide it when the focus moves to a different window.

To try the example, add the following event procedure to a form that has a custom toolbar called CustomToolbar.

Private Sub Form_Activate()
    ' Display custom toolbar.
    DoCmd.ShowToolbar "CustomToolbar", acToolbarYes
End Sub

Private Sub Form_Deactivate()
    ' Hide custom toolbar.
    DoCmd.ShowToolbar "CustomToolbar", acToolbarNo
End Sub