I'm trying to create a data validation routine in my AfterUpdate event on a text box. When the user hits ENTER after keying in the data in my textbox, I test the data against the key field in my file to make sure it exists. If it does, I display a description field in another text box and continue. That works fine. If it doesn't exist in my file, I want to clear the box and have them re-enter the data. I can clear the box, but when I exit the AfterUpdate event routine, the cursor goes to the next field. I have tried using the .SetFocus method and the .GoToControl command, but neither is working. I'm guessing it needs to be in another event routine. Below is my code:
Private Sub CustNumberTxt_AfterUpdate()
CustNameTxt = DLookup("cus_name", "dbo_ARCUSFIL_SQL", "cus_no = '" & CustNumberTxt & "'")
If IsNull(CustNameTxt) Then
CustNumberTxt = ""
CustNumberTxt.SetFocus ' and I've tried DoCmd.GoToControl "CustNumberTxt"
Exit Sub
End If
Me.Requery
Me.Refresh
End Sub
Please help. Thanks.