A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to close form without saving data



 
 
Thread Tools Display Modes
  #1  
Old March 24th, 2008, 04:52 AM posted to microsoft.public.access.forms
Jessica
external usenet poster
 
Posts: 299
Default 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  
Old March 24th, 2008, 05:15 AM posted to microsoft.public.access.forms
Albert D. Kallal
external usenet poster
 
Posts: 2,874
Default 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  
Old March 24th, 2008, 05:20 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:07 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.