Cancel out of edit form

Malcy

Registered User.
Local time
Today, 21:45
Joined
Mar 25, 2003
Messages
584
Hi
I have a form with avout 4 fields based upon a query to allow user to edit an entry if needed.
I want to put a cancel button on so that if they change their mind after having changed a field it reverts to its original value - so for instance they decide to change a land line phone number to a mobile, exit the field but then have a brain storm and decide not to do this so hit the cancel button.
At the moment my cancel button just closes the form (and accepts the overwrite) which would be fine if I am using ADO but not if I am using a bound form.
I am sure there is a simple answer (since I cannot be the only person who thinks this option might be a good idea). I am just not sure how to look for it.
Any thoughts or ideas?
Thanks
 
Look at the Undo Method in VBA.
 
Sounds like the code from simply putting an "undo" command button on the form would do........

Private Sub cmdUndo_Click()
On Error GoTo Err_cmdUndo_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_cmdUndo_Click:
Exit Sub
 
Personally I'd avoid any of the DoMenuItem methods. While they may work, they are really depreciated now, and I'd recommend the newer methods.
 
To undo a form's changes that have started and have not been written yet, use
Code:
 Me.Undo

If you want to give the users a chance to cancel out you can also use the form's BeforeUpdate event to do cancel the changes by using:
Code:
Cancel = True

But, as mentioned by pbaldy, do not use the DoMenuItem command as menus can, and do change in versions (especially going to 2007). For anything you want on a menu, you can use
Code:
DoCmd.RunCommand accmd...
the part after accmd has almost all of the window commands. If you type the DoCmd.RunCommand, and then hit a space, intellisense will give you a drop down of all the commands available.
 
Last edited:
Hi
Sorry so long to get back - too many different projects all competing for too little time.
Me.Undo worked a treat. It is obvious really but I never thought of it!
Thanks for the help
Best wishes
 

Users who are viewing this thread

Back
Top Bottom