Event Procedure on Closing a Form

123dstreet

Registered User.
Local time
Today, 02:17
Joined
Apr 14, 2010
Messages
122
hi everybody! was wondering what event procedure I could possibly use to automaticaly save a forms data when the user closes the form using the 'x' at the top right of the screen, would that be 'on unload' or is there something else I need to use? Thanks a lot
 
You would do it on the Unload event, but if you're form is bound then it should save automatically.
 
Yes the form itself saves automatically, but the report generated from that form does not. I have a button on the form to save the report in pdf to a folder on the network, but i would rather the user not have to hit that button so that the report generated by that form automatically saves into the network folder.
 
Well, you only just mentioned "saving to report". ;) Your approach will cause you more problems than good. I think you should leave that option to the user whether or not he/she wants to save the report. There are times that the user doesn't want a report saved but in your case any report opened must save that report. Think about how many times a report is opened and closed.

You would have to check the directory to see if that file exists before saving. Or Resume Next if you try saving with the same file name.
 
if the report gets prepared by clicking a button, then set a boolean flag to indicate whether the data has been saved or not.

then you can use the forms unload event to test the variable, and stop the form closing. you will need to terst this, as the unload event occurs after the form is saved - but it will probably give you what you want.

this sort of thing
Code:
unload event

if blnReportNotSaved then
    if msgbox("Report Not Saved. Do you still want to close the form",vbyesno) = vbno then
        cancel = true
        exit sub
    end if
end if
 

Users who are viewing this thread

Back
Top Bottom