Run a function on Exit

PiedPiper70

Registered User.
Local time
Today, 17:58
Joined
Oct 21, 2012
Messages
115
Has anyone managed to crack this?

I want to run a function when my application closes. But it must run in all cases, so running it on the last form, or in a hidden form, is not good enough. Even if I'm in design mode with no forms loaded, I want it to run.

For background info - my app is locked down tight against clients poking around. I have got a way for me as developer to get into the "back door", and what I'm trying to do is make sure when I'm finished doing my stuff that the app is locked again without me having to remember to do it.

Any help much appreciated
Thanks
Dave
 
Only thought is to have a hidden form containing your code. This form is the open at start form. When the DB is closed, this forms OnClose event will trigger and run its code.
 
Last edited:
If you don't want to use the unload event of a hidden form approach, I don't see a way of doing what you want.
Why can't you have this hidden form loaded when the database opens and remain hidden. To get the database into the state you're fearing you would have to specifically open this hidden form in design mode, then close it, then change the property allowBypasskey to true and then close the database.
Why not approach this problem from a different angle i.e. when the database opens
Have the autoexec call a startup function which opens the hidden form, sets allowBypasskey to false (I realise that if the database was in the state described above, a knowledgeable user can use the shift key to bypass the autoexec, but the average user doesn't know this and even if they did and previously tried it when it was locked down and therefore not able to bypass, they may just give up on even trying it).
You can still have your back door method but shouldn't involve the use of the hidden form.

David
 
David - I see where you're coming from but there remains the loophole of the shift key. And that's where I got to as well, although by a slightly different route. So I'm beginning to think I'm stuck with what I've got, which is almost there but not quite.

Currently, after doing my work behind the scenes, I need to close the app, then open it (with shift key available to those that know) and close it, and then it's fully locked. I can live with that.
 
PP, why can't you have it so you open it in it's locked down state (ie the shift key doesn't work), when it opens it opens a hidden form which you never see, the hidden form's load event locks it down in case it wasn't, to do your work you use your back door method. Do what you have to do and close the database and the unload event of the hidden form will re-lock it for you. You never see the hidden form .. full stop
I have an app that works precisely this way and I've never had any trouble.
 
I would just put a reminder in a msgbox for you.

msgbox("PiedPiper - have you run your close down functions?)

I don't see how you can have this come up if you close all your forms, and are just in design mode though. The logical place to put it is in your startup form.
 
PP, why can't you have it so you open it in it's locked down state (ie the shift key doesn't work), when it opens it opens a hidden form which you never see, the hidden form's load event locks it down in case it wasn't, to do your work you use your back door method. Do what you have to do and close the database and the unload event of the hidden form will re-lock it for you. You never see the hidden form .. full stop
I have an app that works precisely this way and I've never had any trouble.

I like what you're saying, but after having altered the shift key behaviour I have to close the app, then re-open it while holding down the shift key, and in that case no forms open, not even the one I've designated as the first one to open. If I could find a way of opening a hidden form right there then I can do what you suggest but how?.
 
But what if there are no open/hidden forms?

Add one. It can have just the code if you like.

However it is actually a good idea to keep a bound form open throughout the session as this keeps the connection to the back end alive and helps maintain fast response.
 

Users who are viewing this thread

Back
Top Bottom