See Also Example
Form, check box, combo box , command button , directory list box , drive list box , file list box , grid , horizontal scroll bar , list box , OLE control , option button , picture box , text box , vertical scroll bar .
Occurs when an object loses the focus, either by user action such as tabbing to or clicking another object, or by changing the focus in code using the SetFocus method.
Sub Form_LostFocus ( )
Sub ctlname_LostFocus ([Index As Integer])
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..
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."
Sub Text1_LostFocus ()
' Show non-focus in blue.
Text1.BackColor = RGB(0, 0, 255)
Label1.Caption = "Text1 does not have the focus."