Activate, Deactivate Events -- Event Procedures

Description

To create an event procedure that is executed 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, also make sure to hide the toolbar in response to the Unload event for the form or report, because the Deactivate event doesn’t occur when a form or report is unloaded. Don’t use the GotFocus or LostFocus event to hide a toolbar, because these events aren’t triggered on forms or reports 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.


Private Sub Form_Activate()
    DoCmd.ShowToolbar "CustomToolBar", acToolbarYes    ' Display toolbar.Sub
Sub Form_Deactivate()
    DoCmd.ShowToolbar "CustomToolBar", acToolbarNo    ' Hide toolbar.Sub