Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit form w/out saving record

Status
Not open for further replies.

Stickarm

Programmer
Jun 20, 2001
72
US
How would I allow a user who has already entered data for a new record on a form exit that form without saving that record?
 
Save the key, or any other unique value which identifies the record, in a variable in the Current_Form event. If the user selects to not save the record, find the record based upon the variable and use docmd.delete to delete the record.

mac
 
The Record is not being stored in the table until I exit the form or move to a new record. I want to allow the user to leave the form and not have the data for that record be saved to the table. I tried the Delete method but the record doesn't exist in the table yet, and if the form is just closed then the record gets saved.
 
Have you tried either using a me.Undo before you close the form, or a Sendkeys "{Esc}{Esc}" command to send the escape sequence to the form before closing?
 
Try the CancelEvent method before you update the record.

mac
 
The best way to do it just to create a "Cancel" button with the following code in its click event:

----------------------
if me.dirty then
me.undo
end if

docmd.close
------------------------

the me.dirty property will be true if the user has made changes to the new record. The me.undo method will undo any changes made leaving a blank new record that will not be saved at all when the form is closed. -- Herb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top