I'm using the following code within a form and it is working fine, except for one very minor issue. A user enters data into a textbox ("old_employeeID"). When the control loses focus, it runs the code and (1) checks to make sure that the data entered is not longer than 10 characters, and (2) makes sure that the employee ID being changed matches the current ID in the database. If the data entry doesn't meet the criteria, then the control is cleared with old_employeeID = Null. So far so good, but when I try to reset the focus using old_employeeID.SetFocus the cursor continues on to the next control. I tried a macro to cancel the On Lost Focus event (macCancelEvent), but it doesn't have any effect. I've also tried and adapted the same code for OnExit and it works, but the OK and Cancel buttons on the form stop working--Tab also stops working. Am I missing something about events? Why would buttons stop functioning during the On Exit event? Any advice on getting around this issue? Thanks
--------------------------------------------------------------------
Private Sub old_employeeID_LostFocus()
On Error GoTo Err_old_employeeID_LostFocus
Dim strmsg As String
Dim CurrentID As String
Const max_chars = 10
If IsNull(Forms!frm01b_Change_employeeID!old_employeeID) Then
DoCmd.RunMacro "macCancelEvent"
old_employeeID = Null
Else
CurrentID = DLookup("[employeeID]", "tblUsersList", "User_ID=forms!frm01b_Change_employeeID.User_ID")
If CurrentID = Forms!frm01b_Change_employeeID!old_employeeID Then
If Len(Me!old_employeeID) > max_chars Then
DoCmd.RunMacro "macCancelEvent"
old_employeeID = Null
strmsg = " The EmployeeID you entered exceeds a maximum of " & max_chars & " characters" & Space(20) & _
vbCrLf & " Please correct and Try Again"
MsgBox strmsg, vbCritical, "PTS: EmployeeID"
End If
Else
DoCmd.RunMacro "macCancelEvent"
MsgBox (" EmployeeID is incorrect. Please try again. ")
old_employeeID = Null
End If
End If
old_employeeID.SetFocus
Exit_old_employeeID_LostFocus:
Exit Sub
Err_old_employeeID_LostFocus:
MsgBox Err.Description
Resume Exit_old_employeeID_LostFocus
End Sub
--------------------------------------------------------------------
Private Sub old_employeeID_LostFocus()
On Error GoTo Err_old_employeeID_LostFocus
Dim strmsg As String
Dim CurrentID As String
Const max_chars = 10
If IsNull(Forms!frm01b_Change_employeeID!old_employeeID) Then
DoCmd.RunMacro "macCancelEvent"
old_employeeID = Null
Else
CurrentID = DLookup("[employeeID]", "tblUsersList", "User_ID=forms!frm01b_Change_employeeID.User_ID")
If CurrentID = Forms!frm01b_Change_employeeID!old_employeeID Then
If Len(Me!old_employeeID) > max_chars Then
DoCmd.RunMacro "macCancelEvent"
old_employeeID = Null
strmsg = " The EmployeeID you entered exceeds a maximum of " & max_chars & " characters" & Space(20) & _
vbCrLf & " Please correct and Try Again"
MsgBox strmsg, vbCritical, "PTS: EmployeeID"
End If
Else
DoCmd.RunMacro "macCancelEvent"
MsgBox (" EmployeeID is incorrect. Please try again. ")
old_employeeID = Null
End If
End If
old_employeeID.SetFocus
Exit_old_employeeID_LostFocus:
Exit Sub
Err_old_employeeID_LostFocus:
MsgBox Err.Description
Resume Exit_old_employeeID_LostFocus
End Sub