Order of events--where to put code

  • Thread starter Thread starter Joe Holzhauer
  • Start date Start date
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
 
Nevermind! I moved the code to the Exit event and used Cancel=True to
return to the field. Thanks!
 
We generally use the BeforeUpdate event for validation.
Unlike Exit, it only runs if the user entered something.
 
Back
Top