M
Marshall Barton
Manuel said: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
Undo sets a control's value back to what was in the original
record. If the contol is unbound, there is no value in the
record so nothing can be done. OTOH, Since the control is
unbound, you should know what it's value was before it was
changed and the code can just reset it.