BeforeUpdate Cancel Not Returning to OldValue (1 Viewer)

tomusn83

New member
Local time
Today, 08:48
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
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:48
Joined
Oct 29, 2018
Messages
21,449
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.
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 09:48
Joined
Oct 17, 2012
Messages
3,276
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

Top Bottom