Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / March 2008

Tip: Looking for answers? Try searching our database.

How to close form without saving data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jessica - 24 Mar 2008 05:52 GMT
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
Albert D. Kallal - 24 Mar 2008 06:15 GMT
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...

Signature

Albert D. Kallal    (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com

Allen Browne - 24 Mar 2008 06:20 GMT
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.)

Signature

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.

>I am new to Access and would like a simple way clearly explained on how I
>can
[quoted text clipped - 5 lines]
> my form and not have it save the data that I just put on the form?  Please
> help?  Thanks Jessica
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.