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

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.