problem with cursor returning to field

laurat

Registered User.
Local time
Today, 13:54
Joined
Mar 21, 2002
Messages
120
I have used code to check a field after data is entered. I placed the code in the After_Update of the field:

If Not Orig_Employee_Num = 1234 Then
MsgBox "Not a valid Employee Number, Try again"
DoCmd.GoToControl "Orig Employee Num"
Cancel = True
End If

The problem I am having is the cursor is not returning to the Orig Employee Number field after the message of an invalid number appears. What can I do to fix this?

Also, should I place the code somewhere so that it checks again when the form is closed??
 
Bigger problem!!

What I am trying to accomplish with the code I posted is earlier is perform a check. I have a list of about 10 employee numbers. I need to do a check on the employee number field to make sure one of those numbers was entered. I was going to do

If Not .....1234 Then
MsgBox "Not a valid number"
Else
If Not....9876 Then
MsgBox "Not a valid number"

and so on, this doesn't work though, any suggestions as to how to write the code to accomplish this???
 
Back to original problem

Well I am sorry for all of the posting, I am a basket case today, trying to get this done before I leave for vacation. I am back to my original problem. I figured out the code to do the check however, if the wrong number is entered I would like the cursor to return to the orig employee num field, however right now it is going on to next field.


I also put the code on the close form button and it also does the check and gives the error message if an invalid number is entered but it closes the form anyways. Here is the code on the close button (This code is exactly the same on the after_update of the orig employee num field except for the Do.Cmd.Close)

If Orig_Employee_Num = 7246 Then
DoCmd.GoToControl "Operator Clock Num"
Cancel = True
Else
If Orig_Employee_Num = 1298 Then
DoCmd.GoToControl "Operator Clock Num"
Cancel = True
Else
MsgBox "Not a valid Employee Number, Please enter an appropriate four digit Employee Number"
DoCmd.GoToControl "Orig Employee Num"
Cancel = True

DoCmd.Close
 
Try...

Me.[Orig Employee Num].SetFocus

HTH

You should avoid using spaces in naming your objects.
 
I already tried that with no luck but thank you. I now know not to use spaces but this db was designed about 10 months ago.

Any other suggestions??
 
Orig Employee Num in Subform?

Is the close button on a main form and the field Orig Employee Num in a subform in the main form?
 
I have placed the code in the before_update() event of the form and removed it from all the other places. This displays the error message when the form is closed, however, after the user hits ok on the error message the form closes anyways. Is there any way to stop this from happening? If you need any other info about my database please let me know. THank you.
 

Users who are viewing this thread

Back
Top Bottom