Undo changes

zelarra821

Registered User.
Local time
Today, 03:39
Joined
Jan 14, 2019
Messages
860
Hello people.

I wanted to know if it is possible to undo changes when you change fields.

If you are in a field, you change part or all of the content, but then cancel, what you just entered is not saved. Now, this does not happen if, by doing the same thing, you then change fields. Is it possible to go back somehow?

Thank you.
 
You can try and hit the <Escape> key, or he the key combination <Ctrl>+<z>
 
a control has a OldValue. So until the record is saved you can have a control revert back to its previous value.
 
Last edited:
Sure, but that means duplicating all the fields and for all the forms you have. Can't you save the values in some VBA variable and then retrieve it? Maybe it's simpler, but I don't know how to do it.
 
Code:
Public Function Rollback()
  Dim ctrl As Access.Control
  Set ctrl = Screen.ActiveControl
  ctrl.Value = ctrl.OldValue
End Function

I have this set up in a doubleclick event. I highlight all the controls and in on double click I put
=Rollback()
 
previous value is so useful!! I give Access credit for its concepts of New, Dirty, Next, and previous value and how they can all be used to create beautifully functional interfaces
 
Sure, but that means duplicating all the fields and for all the forms you have. Can't you save the values in some VBA variable and then retrieve it? Maybe it's simpler, but I don't know how to do it.

MajP's answer is how you do it, but it appears you don't understand how a bound field works in Access.

When you navigate your form to a particular record, you start with the Form_Current event, in which Access loads the record's bound fields to TWO places - each bound control's .VALUE property and .OLDVALUE property. What you do on the form can change the .VALUE propery but no manual operation on that form touches .OLDVALUE at any time. So you don't need a separate variable, it is a control property of a bound control.

If you SAVE the record with whatever changes you made, each bound control takes its .VALUE content and puts it in the record, so you just synched the record to the controls on the form. After the SAVE finishes, there will be a new Form_Current event, but due to the SAVE, the form and record already match so this event appears to do nothing.

If you UNDO the record as a whole, each bound controls takes its .OLDVALUE content and puts it in the .VALUE content - which then matches the underlying record - so you just in effect resynced the form to the record. It looks like a Form_Current event just occurred, but it didn't. A new Form_Current event does not occur, but after an UNDO, you couldn't tell the difference anyway.

MajP's suggestion is to use a double-click event to do a selective UNDO operation. This does not affect the form as a whole so you would again not see a Form_Current event as a direct result of this proposed solution. The <ESC> key and <CTRL/Z> key have the effect of a selective UNDO as well. Again, use of these keys does not trigger a new Form_Current event.

NOTE that unbound controls DO NOT have a .OLDVALUE so this discussion does not apply to unbound controls. There, you WOULD have to keep variables for any unbound controls in order to reverse form/keyboard interactions.
 
To be clear I am not suggesting to use the double click event. I only demonstrated using that event. I have no idea what kind of user interface the OP would need to make this useable.
Bottom line you want to be able to undo a specific control and not all controls. So, some how you have to identify which control you want to roll back. You could have a pop up or combobox to pick which to roll back. You could put an event on the right click or have a popup shortcut menu to to this. You could get complicated and log what controls you have visited. Then you could have a single undo button and start undoing in reverse order of which controls where visited. This would be more similar to other applications where you just roll back your entries.
 
How about VBA Transaction methods, BeginTrans, CommitTrans and Rollback
 
How about VBA Transaction methods, BeginTrans, CommitTrans and Rollback
And how would you do that on one control/field?
 
@MajP is correct. If you want to go back and undo any previously modified control, you will need code in some event for EVERY control. The esc method works only for the current control. if you have changed several controls and decide you need to undo the change for a different control than the current one, esc won't work. If you back up three controls and hit esc there, all your changes are undone, not just the one you wanted to back out. If this is the flexibility you want then the double-click is probably the best event to give up for the cause.
Well or you can just write a loop to loop through the controls and see if their text boxes and see if the value is the same as the old value and if not change it back
 
Well or you can just write a loop to loop through the controls and see if their text boxes and see if the value is the same as the old value and if not change it back
Again the question is not about reversing all controls since that is trivial. The question is reversing a specific visited control.
 
Hi guys. Excuse me for answering now.

Once a record is saved, the .OldValue is lost and all you have available is the saved value.

This is the problem. If I modify a field of a record, and go to another field of a different record, it is automatically saved and I can no longer go back with the escape.

I just wanted to ask if there was any possible solution.

The database I'm making is for someone else and they've asked me about it.

I intuited the answer (if it were possible, you would have to write a lot of code and that for each of the forms you have), but I wanted to have the opinion of people who know much more than me.

In my personal databases, I have never considered this.

I will tell you that you have to adapt to the way Access works.

Thank you so much.
 
If I modify a field of a record, and go to another field of a different record, it is automatically saved and I can no longer go back with the escape.
I would like to question what the reason for an unintentional modification is.

Are the fingers faster than the head, the change is unwanted?
You can lock the form against accidental editing. Then switching to permitted editing would be a very conscious decision.

Does the user not know exactly what to enter, tries something and then changes his mind later? In addition to the above note about validating the input, you should help the user as much as possible to do the right thing, e.g. provide selection lists with only valid values.
An undo or an error message means that the user did something wrong. Nobody likes to be told something like this. So you help him to work fluently and correctly.
 
I would like to question what the reason for an unintentional modification is.

Having worked as a tier III support person (as one of many duties) for the U.S. Navy Enterprise Data Center, I can tell you the simplest reason: PICNIC. That was our acronym for "problem in chair, not in computer." People do things and then realize .... "Whoops!" When your staff includes a low-wages clerk who hasn't gone through college but instead gets a REALLY short introductory session on how to use a computer, you have to take into account that they WILL screw up. You can put a LOT of smarts into your application, but the end result will still be that end users are THE BEST stress test you can find for any code. Murphy's Law is based on the simple fact that your end users are humans and humans make mistakes.
 
@zelarra821
you changed the requirement, so you need to be clear. Your initial post was about moving to another field in the same record. Your second post was moving to a new record.
I provided a simple solution for the first problem.
In the second problem you can wrap a continuous form in a transaction, but that still undos all changes.
The only way to reverse a single value on a previous record is doing what @Pat Hartman suggests and create a change log. That is some work but not overly complicated. There are good examples of logging on the web.
 

Once you build the audit trail it would be trivial to build a pop up to pick a field and get a list of previous values. Then click the value you want and update.
 
Harder to implement but Allen Browne's version accounts for most of that.
 

Users who are viewing this thread

Back
Top Bottom