Getting original value of text field when data entry undone with escape (1 Viewer)

Kronix

Registered User.
Local time
Today, 16:04
Joined
Nov 2, 2017
Messages
102
I have subforms that are requeried when the number in a text field on a form is changed using the AfterUpdate event. If the user presses escape on the form after making a change to the text field (regardless of whether that particular text field has focus at the time), I want to requery the changed subforms again using the original value that the field will revert to so that the subforms revert correspondingly. The problem is the Undo event happens before the text field changes back to its original value, so putting the requery into the Undo event will not result in the old value being used. How do I get it to requery using the old value? Is there an event that happens after the value reverts?

Edit: Actually, I have a subform that depends on the text field that automatically reverts when the escape key is pressed. I have a listbox, however, that does not, even though it contains calculations dependent on the text field. I need that listbox to revert the same as the subform.
 
Last edited:

Ranman256

Well-known member
Local time
Today, 10:04
Joined
Apr 9, 2015
Messages
4,339
changing data is live, if the undo cant reset to the original value, then it is lost.
unless you want to restore that 1 record from a backup.
And the backups would have to be very often.
 

Kronix

Registered User.
Local time
Today, 16:04
Joined
Nov 2, 2017
Messages
102
The undo can reset to the original value, but the undo event fires before the original value returns. I need an event that fires after the original value is set, so I can get that original value.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:04
Joined
Feb 19, 2002
Messages
43,223
The undo event does revert to the original value. You want it to revert to the previous changed value. Access doesn't store that anywhere so you will have to handle it yourself. Save the value in a variable in the control's AfterUpdate event. Then you can put it back if the user uses excape to back out the change.

However, this doesn't make any sense to me. You are essentially preventing the user from undoing his change. As long as it makes sense to you.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:04
Joined
Feb 19, 2002
Messages
43,223
The OldValue property is the original value from the existing record. Me.somefieldname.Undo reverts to that value. If this is a new record and there is no saved value then the undo reverts to null.

I'm not sure what changing a value on a main form would have to do with a subform. The connection between the main form and the subform is via the PK of the mainform to the FK of the subform and the PK of the mainform should never be changed.
 

Users who are viewing this thread

Top Bottom