Undo not working?!?

  • Thread starter Thread starter Manuel
  • Start date Start date
M

Manuel

I have an unbound control on a form that the user will enter a date into. In
the BeforeUpdate event I have the below code to check if the date is valid.
If the date is not valid, the user receives a message box and the data the
user entered is "undone". But the "undo" command is not working. I get the
message box but the erroneous date remains. So, if the value in the unbound
field is 5/25/2010 and the user enters 5/263/2010, rather than reverting to
5/25/2010 (which is what I want to have happen) the erroneous data,
5/263/2010, remains. Appreciate any insight as to why the Undo command is
not working. Thanks, Manuel

Private Sub txtStartDtPCT_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
Set ctl = Me.txtStartDtPCT
If Not IsDate(Me.txtStartDtPCT) Then
MsgBox "You have entered an invalid date!", vbCritical, "Date Error"
ctl.Undo
Cancel = True
End If
End Sub
 
I find it's sometimes necessary to issue the Undo command twice:

Private Sub txtStartDtPCT_BeforeUpdate(Cancel As Integer)
Dim ctl As Control

Set ctl = Me.txtStartDtPCT
If Not IsDate(Me.txtStartDtPCT) Then
MsgBox "You have entered an invalid date!", vbCritical, "Date Error"
ctl.Undo
ctl.Undo
Cancel = True
End If
End Sub
 
Back
Top