Macro to close an Access Database

S

steve12173

Is there a macro that can close Access at a certain time? I have an issue
with getting users to close out of my database at the end of the day. So,
something that would automatically close the database, if open, would be a
wonderful feat.
 
S

Steve Schapel

Steve,

One option is to usea Quit macro on the Timer event of a form that is always
open when the application is open. The risk here is that the user will have
left it open with a partly edited record on a form, or some such, in which
case there is the potential for lost data or even corruption if you don't
cater to this as well.
 
S

steve12173

So I can create a Quit macro on the Switchboard (which is always open when
database is open) with a Timer Event? Does anyone have an example of the VBA
on this? I have been using Access for awhile but, I am not used to using
VBA. What I want to happen is, if the database is open to close it 20:00
hours of that machine. I would really like to have everyone's close at 20:00
hours except mine. Have mine run the compact and repair at 21:30 and then
shut down mine at 22:00. Is this possible?
 
S

Steve Schapel

Steve,

Set the Timer Interval to lets say 600000 (i.e. 10 minutes). And then just
put this in the Condition for the Quit macro action...
Time()>#20:00#

As for the different requirement for your own machine, I guess the clunky
answer is to have a different version of the application, with a different
macro condition, running on your machine. Otherwise, we have to get the
macro to detect that it is yours... which I suppose can be done on the basis
of Windows login? Do you actually have a login for the database itself?
What version of Access are you using?
 
S

steve12173

We are using Access 2002 and there is not a log in for the database but, I do
have a module that recognizes the users by their Windows log in. Each user
has their own copy of the Front End of the database on their desktop, linked
to the back end on a Shared Drive. So I think I can use the same Macro for
the front end and then have every user make a copy on their desktop. Then
change mine to add the Compact and Repair of the database and the different
time for the Quit Macro.

What's the signifigance of adding the Timer Interval of 600000? Creating
the Quit Macro and having the condition of "Time()>#20:00#" wouldn't run it
by itself? Is the Timer Interval created in VBA or is that in the Quit Macro
as well? I know I am asking a lot of questions here but, is this better
built in the Macro Builder or in VBA?
 
S

Steve Schapel

Steve,

Having a macro or code running on the Timer event of a form does not have
any effect, unless the form's Timer Interval property is something other
than 0.

Setting the form's Timer Interval to 600000 will mean that Access will run
the macro every 10 minutes. So what this means is that the first time the
macro Condition evaluates to True, the Quit action will be executed. In
other words, between 20:00 and 20:10.

So yes, that's all you need to do, and then it will run itself.

As for whether you prefer Macro or VBA, both are effective. Since you have
posted to a macro newsgroup, I am answering with respect to macro.
 
S

steve12173

Thanks for your help Steve. Works like a charm.

My co-workers thank you as well, I can stop sending emails every hour to
remind them to log off and threatening bodily harm if they don't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top