G
Guest
Hello,
I have a Text Box called txtDate & I want to validate if the user enters in
a valid date & if not to display a msgbox saying "Invalid Date" & keep the
focus until a valid date is entered.
I put the following code which works....
Private Sub txtDate_Exit(Cancel As Integer)
If Not IsDate(txtDate) Then
MsgBox "Invalid Date", vbCritical
Cancel = True
End If
End Sub
However,
If the user enters an invalid date & then clicks the X on the form to close
out the form the msgbox then displays twice & then the Form closes. For some
reason the On Exit Event is getting triggered twice. Is their a way to stop
this from happeneing ? Or idealy for the On Exit Event to not be triggered
at all when the user only closes out the Form ?
I know one way is to use the ValidationRule & ValidationText properties but
I would rather not because you then cant control the way the msgbox looks, as
an example you cant have the vbCritical.
So is their another way ?
Any help would be greatly appreciated.
Thank you,
Jeff
I have a Text Box called txtDate & I want to validate if the user enters in
a valid date & if not to display a msgbox saying "Invalid Date" & keep the
focus until a valid date is entered.
I put the following code which works....
Private Sub txtDate_Exit(Cancel As Integer)
If Not IsDate(txtDate) Then
MsgBox "Invalid Date", vbCritical
Cancel = True
End If
End Sub
However,
If the user enters an invalid date & then clicks the X on the form to close
out the form the msgbox then displays twice & then the Form closes. For some
reason the On Exit Event is getting triggered twice. Is their a way to stop
this from happeneing ? Or idealy for the On Exit Event to not be triggered
at all when the user only closes out the Form ?
I know one way is to use the ValidationRule & ValidationText properties but
I would rather not because you then cant control the way the msgbox looks, as
an example you cant have the vbCritical.
So is their another way ?
Any help would be greatly appreciated.
Thank you,
Jeff