Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetFocus Does Not Work

Status
Not open for further replies.

ARCITS

Programmer
Apr 4, 2002
99
GB
I am using the Exit event of a textbox to check for invalid data as follows:

Private Sub Order_Number_Exit(Cancel As Integer)
If [Order Number].Text = "" Then
MsgBox "ERROR - You Must Enter An Order Number!"
Me.[Order Number].SetFocus
End If
End Sub

The problem is that the MsgBox appears OK but focus is given to the next textbox in the tabindex.

I've tried this with all events and the results are the same!

Any ideas as to what's going on?


Thanks
 
You need to cancel the event in BeforeUpdate of the text box field and check for Null. Here's the code.

Private Sub Order_Number_BeforeUpdate(Cancel As Integer)

If (IsNull([Order Number])) Then
MsgBox "ERROR - You Must Enter An Order Number!"
Cancel = True
End If

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top