Automated on close?

tkpstock

Cubicle Warrior
Local time
Today, 14:29
Joined
Feb 25, 2005
Messages
206
Can you run code on database closure?

I have a database that is locked down pretty tight, but I haven't figured out how to get rid of the close button for the Access application, and I haven't figured out how to run code if they do hit that close button. If they close Access, it bypasses anything that is set to run.

Any help?
 
1. Declare a public variable in a standard module:

Public blnCanClose As Boolean

2. You must have a form (for example a switchboard form) that is open all the time (perhaps hidden when not needed). In the On Unload event of this form, prevent closing it if blnCanClose is False:

Private Sub Form_Unload(Cancel As Integer)
Cancel = (blnCanClose = False)
End Sub

3. Determine how you want to allow the user to quit the database, for example using a Close command button on the switchboard form, and/or using a custom menu item, toolbar button etc. In the code for each of these, call the code you want to execute before closing the database, then set blnCanClose to True, and quit Access.

alternativley you can disable the close button
http://support.microsoft.com/?kbid=300688

HTH

Peter
 
Disabling the close button was the perfect way to go. Works like a dream! Thanks for your help!!!!
 
Disabling the close button

This worked for me as well! I have a db that logs when users log on and off, but if they closed the application without using the "close" button their log-off time would not be recorded. This solved the problem wonderfully!
 
Enable/Disable The Control Box X Button

The form named "fTestCancelFromUnloadEvent" in the sample db will demonstrate how you can prevent a user from closing a form and also the application unless they do exactly what you want them to do.
 
What about a situation when some one right clicks in the taskbar and closes the current form??
He will not be able to close the application window though, so he will be left with closing the whole access process.
I think the function in ghudson's example should also be used on the switchboard or rather login form, to disable the close box.
 
Last edited:
skea said:
What about a situation when some one right clicks in the taskbar and closes the current form??
He will not be able to close the application window though, so he will be left with closing the whole access process.
I think the function in ghudson's example should also be used on the switchboard or rather login form, to disable the close box.
The db should be disabled [programmed] so that the user can not right click on any objects. The user should never be allowed access to the "design" of the db.
 
Last edited:
Thanks ghudson,
Actually i came up with a better solution. To remove the Min-Max-Close Boxes from my title bar.Something i posted in the samples repository.
Then i just disable my Menus and re-enable them when i need them and when i am closing the database.
i also make sure that i set the option to show Windows In taskbar to false.
 
i also make sure that i set the option to show Windows In taskbar to false.

isn't this just a local setting though? If they change it in another DB it will change in yours as well.

Peter
 
Thats why i simply hard-code it.
 

Users who are viewing this thread

Back
Top Bottom