Undo not working?!?

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
 
D

Douglas J. Steele

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
 

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

Similar Threads

Case statement for dates not working 5
not in list 1
CodeNeed 9
Undo: another question 2
Very Simple Date Issue 4
Undo 3
Problems with Dates 3
How to Auto Fill a Text Box with "The One Above" 3

Top