Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form: Exit without saving?

Status
Not open for further replies.

Beard36

Programmer
Sep 4, 2003
69
0
0
GB
I've got a long and complicated problem, but what it boils down to is this -

When a user clicks on the X icon to close a form I want to throw up a question - "Exit without saving?" where either they click Yes and the form closes, any changes they made forgotten, or they click No and the form stays open, the changes they've made remain visible, but the changes are NOT saved to the database.

This is the problem: say the form is open, the user makes a change and clicks X. I put the prompt in Form_BeforeUpdate to try to capture any change saving. If they say Yes (exit without saving) then I go Me.Undo and allow the form to close. If they say No they I need to cancel the update and cancel the close (done by cancel=true in Form_Unload).

This shouldn't be a problem but when I do it, I get the error message -

You can't save this record at this time.

Microsoft Office Access may have encountered an error while trying to save a record.
If you close thie object now, the data changes you made will be lose. Do you want to close the database object anyway?

Yes No

This makes sense in a way I guess - Access' close procedure is to save changes then exit form. When it tries to do this "something" stops it from working as it expects (ie. I've cancelled the update), so it gives me a warning.

If I could just cancel this warning then all my problems would go away (until I find some new ones, at least! ;)

Is this possible?

PS: I'm working on this project in Access and don't have a huge amount of experience with it, which is why I'm struggling with problems like this, and why I've been hammering this forum a little (well, like 3 questions in as many days) - once again, the help given on this board is of much value and very much appreciated. Thanks!
 
This might be a little late but I believe I have a solution for you to help with the closing problem. If you put in the Form Unload event "DoCmd.CancelEvent" it will stop the form from closing. This will catch all form close events (CTRL-F4, CTRL-W and the X button)

Just remember that if you do not have a way in your code to bypass the DoCmd.CancelEvent Access will not close unless you end task.
 
The original poster has probably resolved the issue. However, I do remember this discussion. I had the impression that the poster wanted to control the flow of data between the form and the data source in a very precise way. I encouraged him to avoid binding.
 
I'm afraid that the problem I was having with the closing, etc.. above was not solvable by something simple like you suggested (though a variation on what you have posted did represent part of the solution - the problem was, if I remember correctly myself, that when you clicked on Close, as Form_Unload all of the bound controls have updated their respective values in the db tables, which I didn't necessarily want).

In the end, I followed OhioSteve's suggestion and adjusted my form so that it was unbound from the data source. Once I decided the best way to do this, and had it implemented properly, it became much easier to handle the form the way I wanted to. (So cheers to him for pointing me in that direction!).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top