I have written some code to do the following:

When keying data into a new record and/or clicking onto the "Menu" button, which closes the form.

The User must enter a 3-digit Project Code (text field). If the project code contains a null value, a message appears stating they must enter a 3-digit project code. If the Project code is less than 3 digits, another message appears stating that the Project Code must be 3 digits.

If the user does not enter the 3-digit code or leaves the Provider Code field blank, I want the message box to appear and the cursor placed again in the Provider Code field. If the User enters a 3-digit code, then I want the cursor to be placed in the "Fed Tax ID" field.

***************************

Here's my code placed in the "After Update" and "Lost Focus" of the Provider Code field:

Private Sub Provider_Code_AfterUpdate()
If IsNull(Me!Provider_Code) Then
MsgBox "This Field, 'Provider Code' Must Be Completed. Please Enter A 3-Digit Privider Code!", vbExclamation
Provider_Code.SetFocus
Cancel = True
End If

If Len(Me.Provider_Code) < 3 Then
MsgBox "Please Enter A 3-Digit Privider Code!"
Else: Me.Provider_Code.SetFocus
End If

If Len(Me.Provider_Code) > 3 Then
Me.Fed_Tax_ID__.SetFocus
Else
End If

End Sub

*****************
Here's my code placed in the "After Update" of the "Form":

Private Sub Form_AfterUpdate()
If IsNull(Me!Provider_Code) Then
MsgBox "This Field, 'Provider Code' Must Be Completed. Please Enter A 3-Digit Privider Code!", vbExclamation
Provider_Code.SetFocus
Cancel = True
End If
End Sub


It somewhat works. The messages appears, but the cursor is not placed into the Project Code field if there is a null value or less than 3 digits entered.


Please help. Thanks.