By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

Close the form with out saving

JAMBAI
P: 28
Hi,

I have a MS Access form,and its recordsource is some search query.

When I click the close button (not the X mark) what ever data I typed in the form field are saved into the database.

DoCmd.Close acForm, Me.NAME is the code behind that button click event.

Let me know how to close the form without saving the data.

Thanks
Jambai
Feb 15 '07 #1
Share this Question
Share on Google+
9 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Hi Jambai

You need to run an Undo command first as follows:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
  2. DoCmd.Close acForm, Me.Name
Mary
Feb 15 '07 #2

NeoPa
Expert Mod 15k+
P: 31,492
It's difficult for me to test this atm (& Mary's code will work anyway :)), but try this :
Expand|Select|Wrap|Line Numbers
  1. Me.Dirty = False
  2. Call DoCmd.Close(acForm, Me.Name)
Actually, put it in the OnClose event procedure instead :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.   Me.Dirty = False
  3. End Sub
That way it doesn't matter if the operator does use the forms x.
Feb 16 '07 #3

JAMBAI
P: 28
Thank you so much for your responses.

I tried with Me.Undo, it worked.

Thanks
Kumar
Feb 16 '07 #4

NeoPa
Expert Mod 15k+
P: 31,492
Nice one Kumar.
I'm not absolutely sure if that will work if/when multiple changes are made on the form before it's exited. If you find that's a problem, simply try out the Me.Dirty approach :)
Feb 16 '07 #5

MMcCarthy
Expert Mod 10K+
P: 14,534
Nice one Kumar.
I'm not absolutely sure if that will work if/when multiple changes are made on the form before it's exited. If you find that's a problem, simply try out the Me.Dirty approach :)
I should work for any unsaved changes to the forms data.

Mary
Feb 18 '07 #6

NeoPa
Expert Mod 15k+
P: 31,492
So it's like an UndoAll rather than an UndoLastChange then :)
Feb 18 '07 #7

MMcCarthy
Expert Mod 10K+
P: 14,534
So it's like an UndoAll rather than an UndoLastChange then :)
Essentially if you edit a saved record it will undo all changes and revert back to the saved record.

Mary
Feb 18 '07 #8

P: 2
Hi Jambai

You need to run an Undo command first as follows:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
  2. DoCmd.Close acForm, Me.Name
Mary

But if u didn't type anything and click the close command button message will appear that undo is not available right now...
Aug 30 '08 #9

NeoPa
Expert Mod 15k+
P: 31,492
Me.Dirty tells you if you need to run the undo (Call Me.Undo seems easiest).
Aug 30 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.