Discussion Locked

Access 97-Sense Click on Close

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

In some of my applications I keep track of both when a user logs in to the application and when the user logs out. The theory is that I will know who is actually currently logged in to the application.

Unfortunately, this only works when the users close the application by selecting the quit button on the main menu. (I've disabled the control boxes on forms.) If a user clicks on the close X for the Access window, the application also closes but the application is not aware that the user has selected close and, as a result, does not change the user's status to "not logged in".

How can I either (or both):
1. Disable the close window button and/or control box on the Access window.
2. Sense that the user has clicked the close window button for Access in my application and perform the table update to change the user's status before the application and Access actually close.

9 replies

by bob sellman

This might work if there was only one form, but since the user might (and does) click the Access X (close window) when any form is open, this would require coding every form to handle the situation, not a very practical solution (if there even is a solution).

by timfox

Use the Close event for doing your actual close procedure, but also use the Unload event for form (or in this case system exit validation). This event provides the option of cancelling (Docmd.Cancel Event) the operation, if you need to really make the user exit correctly or validate a last add/update/deletion.
Then the only way (I think!) that user can then screw you is to Ctrl+Alt+Del the app - but then I figure that they've caused the problems that might come about from then on...

TimFox

by bob sellman

This might work if there was only one form, but since the user might (and does) click the Access X (close window) when any form is open, this would require coding every form to handle the situation, not a very practical solution (if there even is a solution).

What's needed is a way to sense that the close Access window 'X' has been clicked and run some code before closing (or even deny closing that way).

by timfox

Sorry - too true!
Obviously we setup Access apps in different ways -I always have a form that is open as long as my application is open.

This method may work for you too, but (as always) it depends on how you want to set it up. I looked for a similar method about 6 months ago, but gave up. Using the Unload event has proved to be a reasonable replacement for my app's - sometimes I use a main menu form (rather than toolbar menu's) for navigation - so I put the Unload routine in that form's code.

I guess you could put the routine in a module and call it from all form's unload events.

Otherwise - I'll keep a subscription on your question in case other solutions come up...

Cheers
TimFox

by bob sellman

Although not the answer I was hoping for, combining your answer with the suggestion in answer 4 provides a work around that should work.

by pancras

stick the unload/onclose event to just 1 form.
Open this form on the start of the application and make this form hidden.
on a normal close (exit button on main form for example) close the form. The onclose/unload events
of this form are also triggered when access is closed.
So here u have your application.terminate event
b.t.w. if u set cancel in the unload event to true, access cannot quit

by bob sellman

Although not the answer I was hoping for, combining your answer with the suggestion in answer 3 provides a work around that should work.

This discussion is closed to new replies.