469,271 Members | 840 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Canceling a form's close event (stopping a form from closing)

PW
Hi,

I want to add code to check if the user wants to save the record
(fields are unbound) when they press the form's close (X) button.

Is it possible to return the user to the form if there are editing
errors?

I am using Access 2003

-paul
Nov 28 '06 #1
4 12624
PW
Nevermind. I was putting the code in the Close event (which can't be
canceled) instead of the UnLoad event (which can).

-pw
Nov 28 '06 #2
Correct: the Unload event can cancel the closing of the form.

That's too late to validate the data though.
The record has already been saved at this point.
Use the BeforeUpdate event of the *form* (not controls).
That's the last event before the data is saved to your table.

--
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.

"PW" <pa********@removewilliamsonenterprises.comwrote in message
news:kk********************************@4ax.com...
Nevermind. I was putting the code in the Close event (which can't be
canceled) instead of the UnLoad event (which can).

-pw

Nov 29 '06 #3
PW
On Wed, 29 Nov 2006 10:15:48 +0800, "Allen Browne"
<Al*********@SeeSig.invalidwrote:
>Correct: the Unload event can cancel the closing of the form.

That's too late to validate the data though.
The record has already been saved at this point.
Use the BeforeUpdate event of the *form* (not controls).
That's the last event before the data is saved to your table.

Allen, thanks for reminding me of that! I forgot to state that the
fields are unbound on this form and I manually write/edit the record.

-paul
Nov 29 '06 #4
Allen Browne wrote:
Correct: the Unload event can cancel the closing of the form.

That's too late to validate the data though.
The record has already been saved at this point.
Use the BeforeUpdate event of the *form* (not controls).
That's the last event before the data is saved to your table.
I've been hoping MS would correct what I consider a little flaw. Using
a bound form, one can have a BeforeUpdate event that will cancel the
save process. However, if one presses the X close button it will pop up
my validation message, cancel the event, but continue on to the Unload
process. It would be great if the B4Update event would truely cancel
the event and stop execution of the close window caused by pressing the
X close.

It's not too bad if one has been editting an existing record. But for a
new record all data is lost by the time it gets to the Unload event.

The OPs problem is with unbound forms and my comment is related to bound
forms.
Nov 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Allan Bredahl | last post: by
1 post views Thread by Chris Bruce | last post: by
2 posts views Thread by Nenad Dobrilovic | last post: by
6 posts views Thread by **Developer** | last post: by
4 posts views Thread by Jimmy | last post: by
11 posts views Thread by Zytan | 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.