469,285 Members | 2,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,285 developers. It's quick & easy.

Close the form with out saving

JAMBAI
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
9 13329
MMcCarthy
14,534 Expert Mod 8TB
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
32,173 Expert Mod 16PB
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
28
Thank you so much for your responses.

I tried with Me.Undo, it worked.

Thanks
Kumar
Feb 16 '07 #4
NeoPa
32,173 Expert Mod 16PB
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
14,534 Expert Mod 8TB
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
32,173 Expert Mod 16PB
So it's like an UndoAll rather than an UndoLastChange then :)
Feb 18 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
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
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
32,173 Expert Mod 16PB
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.

Similar topics

5 posts views Thread by Harry J. Smith | last post: by
4 posts views Thread by Mindy | last post: by
2 posts views Thread by laks | last post: by
9 posts views Thread by Stan B | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.