Skip to content

Latest commit

 

History

History
60 lines (45 loc) · 1.62 KB

enter-exit-events-activecontrol-property-example.md

File metadata and controls

60 lines (45 loc) · 1.62 KB
title keywords f1_keywords ms.assetid ms.date ms.localizationpriority
Enter, Exit events, ActiveControl property example
fm20.chm5225152
fm20.chm5225152
8d3123e3-e5b1-cb8f-0f89-de308c3eecda
11/14/2018
medium

Enter, Exit events, ActiveControl property example

The following example uses the ActiveControl property in a subroutine that tracks the controls a user visits. The Enter event for each control calls the TraceFocus subroutine to identify the control that has the focus.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains the following controls:

Dim MyControl As Control 
 
Private Sub TraceFocus() 
 ListBox1.AddItem ActiveControl.Name 
 ListBox1.List(ListBox1.ListCount - 1, 1) = _ 
 ActiveControl.TabIndex 
End Sub 
 
Private Sub UserForm_Initialize() 
 ListBox1.ColumnCount = 2 
 ListBox1.AddItem "Controls Visited" 
 ListBox1.List(0, 1) = "Control Index" 
End Sub 
 
Private Sub Frame1_Enter() 
 TraceFocus 
End Sub 
 
Private Sub ListBox1_Enter() 
 TraceFocus 
End Sub 
 
Private Sub OptionButton1_Enter() 
 TraceFocus 
End Sub 
 
Private Sub OptionButton2_Enter() 
 TraceFocus 
End Sub 
 
Private Sub ScrollBar1_Enter() 
 TraceFocus 
End Sub

[!includeSupport and feedback]