No Save on Form Close Event

S

SimonCC

I would like to have a form not save and not pop up the save prompt when a
user closes the form. I'm guessing I just need to put some simple code in
the On Close event with the sub form_close(). But I can't find anything that
just says no save. Please let me know what code I can use. Or maybe I'm
approaching this the wrong way by going to the on close event. Please let me
know that was well. Thank you.

-Simon
 
T

TonyT

What save prompt are you getting when you click close?

if me.dirty then
me.undo
end if

will cancel any changes made before you close the form (regardless of
whether you want them saved or not unless you code the save elsewhere)

TonyT..
 
D

Dirk Goldgar

SimonCC said:
I would like to have a form not save and not pop up the save prompt
when a user closes the form. I'm guessing I just need to put some
simple code in the On Close event with the sub form_close(). But I
can't find anything that just says no save. Please let me know what
code I can use. Or maybe I'm approaching this the wrong way by going
to the on close event. Please let me know that was well. Thank you.

By the time you get to the Close event, or even the Unload event, it's
too late to prevent saving the record. The form's BeforeUpdate event is
the last place you can cancel the saving of the record (if it can be
saved).

Is this a form that you *never* want to save the record? In that case,
why not open it read-only, or with it's AllowEdits, AllowAdditions, and
AllowDeletions properties set to No?

Or are you creating a "Cancel" button, to be used in the event the user
doesn't want to save the record they've dirtied? In that case, the code
behind the button could execute the statement

Me.Undo

before closing the form.
 
S

SimonCC

Sorry I didn't make it more clear. It's actually not the record saving that
I'm worried about. Basically I have a subform in the main form, which is
based on a query. So whenever the main form is closed, if there was sorting
or filter change in the subform, it will prompt asking to save query. What I
want is to just close main and subform, without saving the query, and without
the prompt to save query. Hope this clears it up a bit, thanks.

-Simon
 
D

Dirk Goldgar

SimonCC said:
Sorry I didn't make it more clear. It's actually not the record
saving that I'm worried about. Basically I have a subform in the
main form, which is based on a query. So whenever the main form is
closed, if there was sorting or filter change in the subform, it will
prompt asking to save query. What I want is to just close main and
subform, without saving the query, and without the prompt to save
query. Hope this clears it up a bit, thanks.

Okay, I understand now that you're talking about saving/not saving
design changes, not data changes. But I don't see exeactly what you're
doing that causes you to get the prompt. I opened a form with a
subform, filtered and sorted the subform, then closed the main form, and
.... no save prompt. So can you give me a simple scenario to reproduce
the problem?

Sorry about the delayed reply, by the way -- I've been very busy.
 
Top