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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to cancel a form from closing when it's dirty

Status
Not open for further replies.

Schof

Programmer
Nov 18, 2002
103
CA
Currently I have code in the form's BeforeUpdate event to notify the user if the record is dirty, telling them that they must save the record before proceeding. The event is then cancelled and everything works fine.

The problem I need help with is that when the user tries to close a dirty form using the close button (X) in the top right hand corner of the form, after my notification message, MS-Access displays the message:


You can't save this record at this time.
Ms-Access may have necountered an error while trying to save a record.
If you close this object now, the data changes you made will be lost.
Do you want to close the database object anyway?

I have tried putting code in the the form's UnLoad event (as I have seen suggested in a million posts) but the message comes before the event occurs. I have too many forms to remove the close button (X) and manually add my own button control. Any thoughts on how I can handle this would be appreciated.
 
Schof,

It's a bound form. Closing the form will save the record.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Jeremy, how do I cancel the closing of the form then?
 
You can't cancel the close event, but you can cancel the Unload event. =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Do you know how to tell whether the cancel button was clicked or whether the form is in the process of closing? That way instead of trying to cancel the update event I can either undo the changes to the record or allow the record to save and the form to then close.
 
Just a thought...why don't you disable the Close button and force users to click a command button on the form?

Or...in the Unload event check if the command button was clicked and Cancel Unload if not? This will also prevent users from closing the form from File menu or Ctrl+F4...

HTH
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
I know the easy way to do it is to add my own close button to each form but I was hoping to avoid it since I have over 50 forms. Unless I find a way around it (which I will post here) I guess I will have to just invest the tme to do it.

Thx!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top