LostFocus Event

See AlsoULLX8D              ExampleHL9B0L>Low

Applies To

Form14TJ2LN, check box9P3BU5, combo box1YZXFF6, command buttonXJSPC0, directory list boxO9U5A0, drive list box5WJO0PW, file list box1M6S8UX, grid2VGT0PT, horizontal scroll bar1JSJOS7, list boxG11UCK, OLE control2HQDVVU, option buttonJYBO08, picture box31MYIWX, text boxYPYZDG, vertical scroll bar1JSJOS7.

Description

Occurs when an object loses the focus1L3L8ZY, either by user action such as tabbing to or clicking another object, or by changing the focus in code using the SetFocus4AVBOY method.

Syntax

Sub Form_LostFocus ( )

Sub ctlname_LostFocus ([Index As Integer])

Remarks

The argument Index uniquely identifies a control if it is in a control array8G7Y0UU.  A LostFocus procedure is primarily useful for verification and validation updates.  Using LostFocus can cause validation to take place as the user leaves the control.  Another use for this type of procedure is enabling, disabling, hiding, and displaying other objects, as in a GotFocus32EWUCC procedure.  You can also reverse or change conditions that you set up in the object's GotFocus procedure.


See Also

Help:

ActiveControl PropertyJCXG6P

ActiveForm PropertyGCUI9X

GotFocus Event32EWUCC

SetFocus Method4AVBOY

TabIndex PropertyH38QPT

TabStop Property81MAWZ


LostFocus Event Example

The example changes the color of a text box when it receives or loses the focus (selected with the mouse or Tab key) and displays the appropriate text in the label.  To try this example, paste the code into the Declarations section of a form that contains two text boxes and a label..  Then press F5 and move the focus between Text1 and Text2.

Sub Text1_GotFocus ()

   ' Show focus in red.

   Text1.BackColor = RGB(255, 0, 0)

   Label1.Caption = "Text1 has the focus."

End Sub

 

Sub Text1_LostFocus ()

   ' Show non-focus in blue.

   Text1.BackColor = RGB(0, 0, 255)

   Label1.Caption = "Text1 does not have the focus."

End Sub