Force to click save button before form close

farey

New member
Local time
Tomorrow, 02:45
Joined
Aug 3, 2015
Messages
4
I have couple of subforms on my mainform. I use Count(textboxes) on each subform to count records entered on sunforms and then count all subforms total in mainform Count(txtbox). Problem is, subforms count when user loses focus from the current record so if user just enters data in subform and closes mainform, count is not done on mainform (it does when i open mainform later or when i click savebutton on mainform). I have a code on mainform unload event which tells user that there are no records and one value in mainform combox will be changed to a value i mention in my mainform unload event. So when user closes mainform, this message pops up as it does not count if user do not move to another record in subform or do not click mainform. Which means it changes my mainform combobox value, which is an issue. So i want force user to click mainform savebutton before closing mainform. Or is there another way to ensure this?
 
Well, you can remove Close button from the form in form properties and add a button of your own to close the form (Docmd.Close acForm, Me.Name) and call your save routine ahead of the close command.

Alternatively you can have the Close button disabled until the user saves the record, have enable close in your save routine.

What I don't think you can do is stop users from closing the application without hitting save.
 
If I've understood you correctly, I think you can do this with your unload event. If you have a global boolean that gets set to false when the main form loses focus, and true when the user clicks your save button, then you can invoke cancel if it's not true, and stop the form from unloading... This should even handle the user trying to close the Access application.
 

Users who are viewing this thread

Back
Top Bottom