If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How to close form without saving data
I am new to Access and would like a simple way clearly explained on how I can
code the close button on my form to close with out saving the data that I entered(not updated). ie I am adding a new record and realize that I don't want to add this record to my database so I want to click the close button on my form and not have it save the data that I just put on the form? Please help? Thanks Jessica |
#2
|
|||
|
|||
How to close form without saving data
The normal way is to hit the esc key to undo changes (or, use the menu and
go edit-undo). If you **really** want to place a button, then you can use the following code. However, it likely better to teach/train the users to use the ESC key, or the edit-undo, since that will work for ALL forms. Otherwise, for virtually for EVERY form and application you make, you have to add a button called: Exit without Save. and, if they use an access application written by someone else, they not have that button, and once again, you would have been better off to teach the users about edit-undo.... Anyway, here is the code that you can place behind a button that will Exit without save (thus, it will work for existing records, and new ones ). If IsNull(Me!ID) = False Then If Me.Dirty = True Then Me.Undo End If End If DoCmd.Close note: replace !ID with the name of the primary key used for the the forms recordsource (table) Lets just hope users don't start hitting that button...and you be back here in a week asking why so many users are complaining that the record did not get saved/added... -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada |
#3
|
|||
|
|||
How to close form without saving data
1. Set the command button's On Click property to:
[Event Procedure] 2. Click the Build button (...) beside this. Access opens the code window. 3. Set up the code like this: Private Sub Command1_Click() If Me.Dirty Then Me.Undo DoCmd.Close acForm, Me.Name End Sub That will work unless Access has already saved the record before you click the button. There are many things that could cause this to happen, e.g. tabbing through the last control on the form (so it moves to the next record.) -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Jessica" wrote in message ... I am new to Access and would like a simple way clearly explained on how I can code the close button on my form to close with out saving the data that I entered(not updated). ie I am adding a new record and realize that I don't want to add this record to my database so I want to click the close button on my form and not have it save the data that I just put on the form? Please help? Thanks Jessica |
Thread Tools | |
Display Modes | |
|
|