set focus for field just losing focus

  • Thread starter Thread starter AngiW
  • Start date Start date
A

AngiW

I have a field, txtEID. When a user tabs out of the field, it checks to see if
the employee is eligible for this form. If not, a vbOkOnly message box pops
up. When they press ok, I want the same field to have the focus again. It's
not working. Here's some of what I have in the txtEID_LostFocus event:

Response = MsgBox(Msg1, Style, Title)
If Response = vbOK Then
txtEID.SetFocus
End If
 
AngiW said:
I have a field, txtEID. When a user tabs out of the field, it checks
to see if the employee is eligible for this form. If not, a
vbOkOnly message box pops up. When they press ok, I want the same
field to have the focus again. It's not working. Here's some of
what I have in the txtEID_LostFocus event:

Response = MsgBox(Msg1, Style, Title)
If Response = vbOK Then
txtEID.SetFocus
End If

Use the control's Exit event instead, and just set the event procedure's
Cancel argument to True.

Private Sub txtEID_Exit(Cancel As Integer)

' ...

Response = MsgBox(Msg1, Style, Title)
If Response = vbOK Then
Cancel = True
End If

End Sub
 
Dirk,
That worked of course. But how can I clear the name that was in there when it
cancels? Or at least make it so they can start typing a new name (highlight
it).

Thanks!
 
Back
Top