See Also Example
Applies To
Form, check box
Description
Occurs when an object loses the focus
Syntax
Sub Form_LostFocus ( )
Sub ctlname_LostFocus ([Index As Integer])
Remarks
The argument Index uniquely identifies a control if it is in a control array 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 GotFocus procedure. You can also reverse or change conditions that you set up in the object's GotFocus procedure.
Help:
ActiveControl Property
ActiveForm Property
GotFocus Event
SetFocus Method
TabIndex Property
TabStop Property
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