Order of events--where to put code

J

Joe Holzhauer

I'm designing a patient database, and I have a field called PatientID. The
user enters a patient ID value, based on which I populate some patient
information fields. I have my code in the LostFocus event handler so that
no matter where the user clicks after entering the ID, it will still work
correctly.

However, if the field is left blank or the ID is not found, I can't get the
focus to return to the patientID field. I've tried txtPatientID.Undo and
txtPatientID.SetFocus.

Is there another command I should use, or should I put the data checking
code in another event (such as txtPatientID.Exit or .Change)?

Joe
 
J

Joe Holzhauer

Nevermind! I moved the code to the Exit event and used Cancel=True to
return to the field. Thanks!
 
A

Allen Browne

We generally use the BeforeUpdate event for validation.
Unlike Exit, it only runs if the user entered something.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top