Visual Basic Reference

LostFocus Event

See Also Example Applies To

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.


Private Sub Form_LostFocus( )

Private Sub object_LostFocus([indexAs Integer])

The LostFocus event syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
index An integer that uniquely identifies a control if it's in a control array.


A LostFocus event procedure is primarily useful for verification and validation updates. Using LostFocus can cause validation to take place as the user moves the focus from the control. Another use for this type of event procedure is enabling, disabling, hiding, and displaying other objects as in a GotFocus event procedure. You can also reverse or change conditions that you set up in the object's GotFocus event procedure.

If an .exe file built by Visual Basic displays a dialog box created by a .dll file also built in Visual Basic, the .exe file's form will get Deactivate and LostFocus events. This may be unexpected, because you should not get the Deactivate event:

  • If the object is an out-of-process component.

  • If the object isn't written in Visual Basic.

  • In the development environment when calling a DLL built in Visual Basic.