Setting focus after on exit

  • Thread starter Thread starter Richard Mask
  • Start date Start date
R

Richard Mask

I got this to work but was wondering why I had to go to a control after the
control I was checking for null and then set focus back to that control.

Private Sub TrailerNumber_Exit(Cancel As Integer)
If IsNull(Me!TrailerNumber) Then
MsgBox "You must enter a Trailer Number"
End If

DoCmd.GoToControl ("TruckLine")
TrailerNumber.SetFocus

If I , DoCmd.GoToControl (TrailerNumber) or try to
Setfocus back to the TrailerNumber control it always goes to
the next control TruckLine But the above sets focus back to the
TrailerNumber control properly. I hope this makes sense.
 
You don't. You need to cancel the event. Here's some sample code in one of
mine:

Private Sub txtDuration_Exit(Cancel As Integer)
If Len(Me.txtDuration & vbNullString) = 0 Then
MsgBox "You must set a value for the Duration", vbOKOnly
Cancel = True
Me.txtDuration.SetFocus
End If
End Sub

--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Thanks
Arvin Meyer said:
You don't. You need to cancel the event. Here's some sample code in one of
mine:

Private Sub txtDuration_Exit(Cancel As Integer)
If Len(Me.txtDuration & vbNullString) = 0 Then
MsgBox "You must set a value for the Duration", vbOKOnly
Cancel = True
Me.txtDuration.SetFocus
End If
End Sub

--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top