Undo Upon Exit

Earl C Phillips

Volunteer Programmer
Local time
Today, 08:28
Joined
Jul 18, 2008
Messages
40
I have forms that are used to enter data to a table. After clicking on the "Add" button, it adds the record and clears the form. But, if user does not click on "Add" and instead clicks on "Return to Main", if anything is left on the form it writes a record containing whatever is left, in spite of a Me.Undo in the code.

Me.Undo
DoCmd.CancelEvent
'Close the Modify Participants page
strDocName = "frmModParticipants"
DoCmd.Close acForm, strDocName, acSaveYes
'open main form to start over
strDocName = "frmMain"
DoCmd.OpenForm strDocName, , , strLinkCriteria

How can I limit the write to the tables so only the "Add" button works?

Help the Community Food Bank feed the hungry.
 
What event is that in? It would need to be the before update event.
 
Click of "Return to Main" command button.
 
Should I change the code to call the Before_Update code to Undo the data entry?
 
That's the normal method, using a form level variable to determine whether the save button was clicked or not. The cancel bit only works on events that can be cancelled, and the click event of a button can't.
 
Too many habits left over from the mainframe days. Obviously still in the learning state. Thanks for the help. :o
 
No problem. We're all still learning. Post back if you get stuck.
 

Users who are viewing this thread

Back
Top Bottom