BeforeUpdate Cancel Not Returning to OldValue

tomusn83

New member
Local time
Today, 02:08
Joined
Jan 9, 2014
Messages
7
Good day. Either I'm not interpreting the BeforeUpdate event docs correctly or it doesn't work as described. Here's a line from the docs:

If you cancel an update, the value of the OldValue property replaces the existing value in the control.

Sorry, I don't have enough posts to be able to post links but it is the Form.BeforeUpdate article in the standard Microsoft documentation.

The following code will output the debug statement and cancel the update when txtStartDate is before today but it does not revert to the OldValue as it states in the documentation. Doing an undo on the control works but I'm wondering why it isn't reverting back with the cancel as advertised.

Code:
Private Sub txtStartDate_BeforeUpdate(Cancel As Integer)
  If Me.txtStartDate < Date Then
    Debug.Print "Start date earlier than today"
    Cancel = True
  End If
End Sub

Thank you,
Tom
 
Hi Tom. I guess the documentation could have just said it will prevent the change from being saved/committed into the table if you set Cancel = True but the change is still active until you perform an Undo.
 
Cancel simply cancels the event that was triggered.

To undo the change that was done, you need to use the Undo event:

txtStartDate.Undo
 

Users who are viewing this thread

Back
Top Bottom