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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Msgbox, vbCritical - goes to next field anyway

Status
Not open for further replies.

jfrizelle

Programmer
Jan 15, 2004
26
0
0
IE
Hi - when I display a message box showing an error, how do I prevent focus from moving to the next field?

I have the following code (thanks to MakeItSo!) :

If DCount("Emp_Id", "qry_Employee_Passed_Course") > 0 Then
MsgBox "That employee sat and passed this course within the last 2 years", vbCritical, "Error"
End If

I would have thought the vbCritical style of message would prevent the focus from moving away from the employee field, but no - it goes on to the next field.

I've put this code into the Emp_Id_Exit event, but then I can't get away from the Emp_Id field, even by pressing Esc. I know it's something simple, but just can't get it.

Thanks,
Jenne.
 
Hi

Move it into the Emp_Id_BeforeUpdate event, then put the lines

Cancel = True
Emp_Id.SetFocus

immediately before "End If"

this will stop it getting saved and move the cursor back to the field.

John
 
Hi John,

You don't need to set the focus in the BeforeUpdate Event. Cancel=True tells Access the field is in error, the update is disallowed, and any queued shifting of focus is suppressed, the focus remaining on the field in error.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Hi John

It wouldn't allow the Emp_Id.SetFocus line (Error - you must save the field before you execute the ... SetFocus method), but moving it into the Before_Update event and setting Cancel = True sorted it.

Thanks for your help.
Jennie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top