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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Exit Without Saving" Command Button?

Status
Not open for further replies.

KerryL

Technical User
May 7, 2001
545
US
Is there a good way to create a command button that allows a user to exit a form without saving what they've entered or edited on the form?

A standard "Close Form" command button automatically saves the data, which is what I'm trying to avoid. I'd like to give users the option of exiting the form without saving what they've done.

Thanks for any insight you can provide.

Kerry
 
Hi Kerry!

In the code for the click event of the command button:

If MsgBox("Are you sure you want to discard the data?", vbYesNo) = vbYes Then
Me.Undo
DoCmd.Close acForm, Me.Name
End If

This also give the user the option of going back to the form with the data still intact.

hth
Jeff Bridgham
bridgham@purdue.edu
 
I have a subform that refreshes itself after new record is added to the main form. I've tried to add in the code that was suggested, in the on_click event of the close command but the whole database was exited when I selected 'Yes', and the record was saved.

Shouldn't it not save the record and just close the form?
Pls advise.
 
I have a subform that refreshes itself after new record is added to the main form. I've tried to add in the code that was suggested, in the on_click event of the close command but the whole database was exited when I selected 'Yes', and the record was saved.

Shouldn't it not save the record and just close the form?
Pls advise.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top