Full Version: Prevent Users From Using Windows Taskbar To Shutdown Db
UtterAccess Forums > Microsoft® Access > Access Forms
Groundrush
Anyone know how to prevent users from right clicking on the database icon on the windows taskbar & selecting close?
prefer the users to exit the database through the database switchboard or various exit cmd buttons located on every form - I do this to keep a log of users that are logged in & who have logged out
I want not work out why some users where logged in more than once. It now appears that some users close the database via the windwos taskbar preventing the user record being logged as exiting the database
I'm now worried that this method could corrupt the database.
CyberCow
Instead of determining if the "X" is clicked, I take a more proactive approach and PREVENT the "X" from being activated by setting each form's 'OnUnload' event property to evaluate the the state of a global boolean variable I named "myOKtoClose".
Create a global boolean variable named (say): "myOKtoClose"
At app start up, "myOKtoClose" is set to false and each form has the following line in the OnUnload event (in VBA):
If Not myOKtoClose Then Cancel = True
This prevents the form from closing, effectively disabling the user's ability to close Access by clicking on the 'X'.
To allow any form to close, I place a command button that says "Close" in its caption and set the folloing 'OnClick' event in VBA:
myOKtoClose = True
DoCmd.Close acForm, Me.FormName

And, in each form's "OnClose" event:
' Now reset the myOKtoClose back to False
myOKtoClose = False
Then finally, to quit the application, I supply the users with a "Quit" captioned command button that has the following in its 'OnClick' event:
myOKtoClose = True
DoCmd.Quit
hope this helps
Groundrush
Hi
This looks promising
Can you explain exactly what you mean by creating a global boolean variable please?
Thanks :-)
BananaRepublic
You should also take in consideration that you can't stop the user giving your application the three-finger salute and even if they did cooperate and follow along, there's no guarantee that there won't be a case where someone trip over the power cord or something like that, leaving you with mismatched logs due to abnormal terminations. Therefore if you want to keep the record of who logged in/out, you have to accept that there will be some uncertainty over a genuine abnormal termination beyond user's control vs. forceful termination by the user.
If you're finding that your users are closing your application abnormally, you may want to find out why - if they find that exiting the database normally is too frustrating, they may end up using other methods that you don't want to use.
Just a thought.
Groundrush
Hi,
Yes that's fine, most users close down correctly & sometimes when the system freezes then Alt/ctrll/del is is used causing the user to stay logged in.
I'm just trying to improve the system the best I can.
I think people just want the quickest or sometimes it may be a habit to right click on the Widnws taskbar without realizing the problems it causes
vtd
This is actually the standard feature of the OS where user can close the application using the icon in the TaskBar. If you want to go the non-standard way, it is actually possible to disable the Access Application Close button (top-right X button) and in this case, the user cannot use the Access Application icon in the (Windows) Taskbar to close Access/your database application. This works with Access 2003 and earlier but IIRC, this may not work with Access 2007/2010.
Search Google for "Disable Access Application Close button" and you should find some links to the relevant Web pages that has the required Windows API code. If you can't find it through Google search, post back and see if I can find the link in my notes or the code.
Groundrush
Hi,
don't have a problem with the close button on the database itself, it's the Windows task bar that is causing me problems.
Groundrush
It's the windows taskbar that is causing the problem not the X close icon on the database itself
vtd
>>I don't have a problem with the close button on the database itself, it's the Windows task bar that is causing me problems. <<
The Access Application Close button (X) and the TaskBar icon are linked together. If you right-click any application icon in the TaskBar, you will see one of the options is "Close". When the Access Application Close button is disabled, this "Close" option in the right-clicked menu of the TaskBar icon is also disabled and the user won't be able to close the Access application using the TaskBar icon.
BananaRepublic
Also, I believe when they close via Windows Taksbar, the form's Unload event will still fire so you have an opportunity to cancel as CyberCow explained. Whether they clicked the X or via Windows taskbar is immaterial because they do same thing and can be cancelled or disabled as vtd explained.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.