472,364 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

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 12836
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Allan Bredahl | last post by:
Hi All I am trying to construct an application that is able to cancel a machine shutdown, reboot or logoff. And after performing some stuff to perform the original shutdown order :...
2
by: Denise | last post by:
How do I get the report to not spend time pulling up the data when I'm going to bail out of the report anyway? Below is the code in my report. I first show the user a form where they can select...
5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
1
by: Chris Bruce | last post by:
In my application I need a way to distiguish between the following events: 1. When a user closes an MDI child window. 2. When the user closes the MDI parent window which subsequently closes the...
2
by: Nenad Dobrilovic | last post by:
Hi, is there any way to find out how form was closed (by calling it's method Close() or by clicking on the 'close' button in control box)? Also, can I close the form in that way that Cloing/Closed...
5
by: Oenone | last post by:
I have a VB.NET form which I'm displaying modally using the ShowDialog() method. Within the form is a Cancel button, and I've set this button into the Form's CancelButton property so that...
6
by: **Developer** | last post by:
I've been looking but can't find out how in a form Closing event to know if the closing is because the form's "X" had been clicked or the main form's "X" was clicked. That is, I need to know if...
4
by: Jimmy | last post by:
Quick question for you. I'm using a small form for users to input a range of dates for a report (similar to the date range forms used in MS templates) that has an ok and a cancel button. How can I...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.