save on close problem

human_anomaly

Registered User.
Local time
Today, 01:03
Joined
Apr 12, 2004
Messages
69
I an adp database that is connected to an sql server. I have a form that lets the user edit records. I want the user to be given the option to save their changes when closing the form. My code does something like this:

form_beforeUpdate method ()
check for changes
ask user if they would like to save changes
if yes then check for missing data
if there is missing data ask the user if they would like to save with the missing data or add the missing data to the form
if the user wants to add the data then cancel = true and exit sub
else save the data

Now I this method also runs when the user switches between records and it works fine; however when this method runs when the form is being closed I have a problem. The problem is that if the user has some missing data and they want to go back and add the data instead of closing the form and saving it does let them go back and add the missing data, but it also discards all the changes that they have mades so far (which is the problem). This seems to occur as soon as the Form_Unload event occurs. Is their any way, while in the beforeUpdate event, of telling the unload event to not run? Or does anyone know why the changes are being discarded? If there is anything I can clear up let me know. Thanks in advance.
 
You need to cancel the BeforeUpdate event if you do not want the form to close or for the record to be saved. Add this to your code for when you want to cancel the BeforeUpdate event so that it prevents the current record from being saved and also from allowing the form to be closed.

Code:
DoCmd.CancelEvent
This might be of some interest to you... Enable/Disable The Control Box X Button
 
Yes the cancel = true does the same thing, but I tried cmd.cancelEvent just to make sure. It cancels the current event you are in, which in my case is beforeUpdate. But I need to make sure it doesn't start the Unload event, or find out what is changing the records back.
 
I have a method that I developed to prevent my user's from moving to a new record or from closing a form if the record is dirty.

Check this out... A better mouse trap?
 

Users who are viewing this thread

Back
Top Bottom