Running code when a database closes 
Author Message
 Running code when a database closes

How do I make sure that a certain function runs when a database is closed.
I have a exit button on the menu but there are so many other ways to close
the database. Any help would be appreciated.
--
Rohn




Tue, 25 Jul 2000 03:00:00 GMT  
 Running code when a database closes

Hi,

Here's something I wrote up.  Using this, you can put your code behind the
OnUnload event of the form.  Hope it may help
(Q) I want to make sure that users always exit my database using the Exit
button provided on my Switchboard.  However,  I'm not able to prevent them
from closing Access itself.  Is there a way to control how they exit Access?
(A) You can use the  UnLoad event of a form to do this.  If your switchboard
is the first form to open and always remains open in the background, you can
apply the following method on the switchboard. Otherwise, I would recommend
creating a hidden form for this functionality.
Define a new variable in a new module
Public pboolCloseAccess as Boolean
Now, when you open the database, set
pboolCloseAccess=False
In your (Switchboard/Hidden) Form's Unload Event, set the variable to true
and also check for its value
pboolCloseAccess=True
DoCmd.Close acForm, "hfrmCloseAccess"
docmd.Quit
If your Switchboard form closes during one instance, then create a new form
(hfrmCloseAccess). You can minimize the size if you want because it will be
in hidden mode. Type the following in hfrmCloseAccess's OnUnload Event
if not pboolCloseAccess then cancel = true
Create the Autoexec macro. If you already have one, make sure that you open
hfrmCloseAccess before anything else IN HIDDEN MODE.
The reasoning here is, when someone clicks X in Access's window, the System
starts closing down all open objects in a first-open-last-close basis. Since
your hfrmCloseAccess form is the first one to open, it will be the last to
close. And since the boolean var is still False, Cancel will always be true,
hence Access will not close. On the other hand, when the user clicks on the
Exit button or closes your switchboard, you're setting the boolean var to
True and then closing the hfrmCloseAccess form, which WILL close now  and
hence Access will close itself.

HTH

--
Just my $.001
Dev Ashish
---------------

:How do I make sure that a certain function runs when a database is closed.
:I have a exit button on the menu but there are so many other ways to close
:the database. Any help would be appreciated.
:--
:Rohn
:



Tue, 25 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Close CurrentDatabase but keep code running

2. Running Code when Access Closes?

3. Access97 won't close after running DAO code

4. Running code on opening and closing files

5. Running code from a closed file

6. Running template code after closing the document

7. Open a second database and allow autoexec to run then close

8. can't work on code and close database

9. How to close the database window by code...

10. Close current database using VB code?

11. Close database window Code

12. Close database window Code

 

 
Powered by phpBB® Forum Software