J
John S. Ford, MD
I've written an event handler to ensure that a user doesn't enter a patient
discharge date the doesn't occur BEFORE the admission date (which is
illogical). I'm using the OnExit event for a TextBox called
txtPatientDischargeDate.
If the user enters a bad date, the MsgBox opens up and the TextBox gets the
value of "". The problem is that when the MsgBox is closed, the focus goes
to the NEXT control in the tab order rather than staying on the original
TextBox. This is confusing to the user and necessitates an extra mouseclick
to get the focus back. What is wrong with this code? Why doesn't the
SetFocus line work?
Am I using the wrong event to trigger my code?
Private Sub txtPatientDischargeDate_Exit(Cancel As Integer)
If txtPatientDischargeDate.Value < txtPatientAdmitDate.Value Then
MsgBox "discharge date must be LATER than admission date."
txtPatientDischargeDate = ""
txtPatientDischargeDate.SetFocus
End If
End Sub
John
discharge date the doesn't occur BEFORE the admission date (which is
illogical). I'm using the OnExit event for a TextBox called
txtPatientDischargeDate.
If the user enters a bad date, the MsgBox opens up and the TextBox gets the
value of "". The problem is that when the MsgBox is closed, the focus goes
to the NEXT control in the tab order rather than staying on the original
TextBox. This is confusing to the user and necessitates an extra mouseclick
to get the focus back. What is wrong with this code? Why doesn't the
SetFocus line work?
Am I using the wrong event to trigger my code?
Private Sub txtPatientDischargeDate_Exit(Cancel As Integer)
If txtPatientDischargeDate.Value < txtPatientAdmitDate.Value Then
MsgBox "discharge date must be LATER than admission date."
txtPatientDischargeDate = ""
txtPatientDischargeDate.SetFocus
End If
End Sub
John