Run code automatically when last user exits?

M

mscertified

I need to run a piece of code automatically when the last user exits a
multi-user database. How could I do this? There is currently no table that
tracks logged on users.

Thanks.
 
J

Jeff Boyce

Again, you've described "how" you want to do something (run code when the
last user exits). Why? What does that code do? I ask because there may be
other ways to meet the underlying need.

If you want a table to track users (aside from using the .ldb file, which
tracks users), you could create one. It might even be enough to have a
single numeric field, defaulted to zero. When each person logs on, the
count is incremented. When each person logs off, the count is decremented,
and, if zero, your code runs.

But what would you do to handle the situation when someone's copy of Access
crashes and they bail without using your "exit" routine?!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
K

Klatuu

I can't find the link, but out in the world somewhere is a a sample mdb
named whoseon. It reads the ldb file and returns the number of users logged
on as well as a list of their user names. If you can find this code, you
could incorporate it into you application to determine how many users are
logged on.
This would require you have a form that is always open so that you would
have an event that will fire when you close the application. I think that
form's Unload event might be the place to do this.
 
M

mscertified

What I need to do is to run an 'export' (TransferText) once per day. Since
this is a multi-user application I would think I need to determine when the
first person logs on or the last person logs off. It seems less painful to
run it at logoff time since it may take a minute or so to run. If you have a
better way, I'd love to hear it. Either way it MUST run once and once only
per day. Yes, the application is used every day.
 
J

Jeff Boyce

Here's the risk of adding it to the close-out (last person leaving)...

If someone (who happens to be the last person leaving the app) shuts down
the app and then shuts down their PC (?end of work-day scenario?) BEFORE the
routine finishes, the proper shut down routine could be seriously munged.

If, on the other hand, you made the routine run once, on startup, only for
the first startup of the day, the person is already expecting a bit of
delay. You could even add a message that explains what it's doing. And if
you add a date/timestamped record to a table when the routine runs, then the
first thing the app does when ANYONE starts it is check to see if your
routine has already run on <today's> date.

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
C

Clddleopard

How do you do this? I've been looking for some way to do exactly this, but
I'm not sophisticated enough of a user to come up with it myself.
 

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