Enter, Exit Events

Applies To

CheckBox control, ComboBox control, CommandButton control, Frame control, ListBox control, MultiPage control, OptionButton control, ScrollBar control, SpinButton control, TabStrip control, TextBox control, ToggleButton control.

Description

Enter occurs before a control actually receives the focus from a control on the same form. Exit occurs immediately before a control loses the focus to another control on the same form.

Syntax

Private Sub object_Enter( )

Private Sub object_Exit( ByVal Cancel As MSForms.ReturnBoolean)

The Enter and Exit event syntaxes have these parts:

Part

Description

object

Required. A valid object name.

Cancel

Required. Event status. False indicates that the control should handle the event (default). True indicates the application handles the event and the focus should remain at the current control.


Remarks

The Enter and Exit events are similar to the GotFocus and LostFocus events in Visual Basic. Unlike GotFocus and LostFocus, the Enter and Exit events don't occur when a form receives or loses the focus.

For example, suppose you select the check box that initiates the Enter event. If you then select another control in the same form, the Exit event is initiated for the check box (because focus is moving to a different object in the same form) and then the Enter event occurs for the second control on the form.

Because the Enter event occurs before the focus moves to a particular control, you can use an Enter event procedure to display instructions; for example, you could use a macro or event procedure to display a small form or message box identifying the type of data the control typically contains.

Note To prevent the control from losing focus, assign True to the Cancel argument of the Exit event.

See Also

SetFocus method.

Example

See the ActiveControl property example.

Example

See the ColumnWidths property example.