Preventing mulitple instances of Access Database

G

Guest

Our database is running on a single workstation. It is an Windows XP based
system with only one account. Pretty straight-forward (I think). I need to
prevent the user from inadvertently opening a second or third or fourth
instance of the application (users are not highly skilled computer users).
 
L

Lorenzo

A very simple method can be to open a dummy file in exclusive mode.
If a user open other istance of the application the system prompt and close
the secondary istance.
Put in main startup code or in open event of your main form :

On Error GoTo noduplicate
close #1
Open "path\dummy.pid" For Output Access Write Lock Read Write As #1
On Error GoTo 0

noduplicate:
msgbox "Another application is running"
Application.quit

If this can help you
Lorenzo
 
J

Jeff Conrad

Hi Bob,

I'm sure there are lots of ways to do this, but here is the method I use.

1. Copy and paste all the code to a new standard module.

2. Compile the code and save the module as modCheckMultipleInstances.

3. Create a new macro.

4. In the Action column select RunCode from the drop down list.

5. A new box in the bottom left corner will appear asking for a function name.

6. Enter this in the Function name box: =winCheckMultipleInstances(False)
(Include the equal sign)
Now I selected False which meant there is no prompt to the user.
You can experiment with True to see what that does.

7. Now save the macro with a name called Autoexec.
With this name, this particular macro will fire any time this database is opened, unless of course
they hold down the shift key. (That can be disabled as well) If you have already created an Autoexec
macro just add this RunCode option at the bottom of any existing elements.

8. Make sure you set an application title under Tools | Startup | Application Title

9. Now save everything and close the database

10. Open the database, minimize, and then try and open another instance.
You should see some screen flickering, but only one instance in the Task Bar should show.

Hope that helps,
 
G

Guest

Thanks again Jeff. It works perfectly.

Bob

Jeff Conrad said:
Hi Bob,

I'm sure there are lots of ways to do this, but here is the method I use.

1. Copy and paste all the code to a new standard module.

2. Compile the code and save the module as modCheckMultipleInstances.

3. Create a new macro.

4. In the Action column select RunCode from the drop down list.

5. A new box in the bottom left corner will appear asking for a function name.

6. Enter this in the Function name box: =winCheckMultipleInstances(False)
(Include the equal sign)
Now I selected False which meant there is no prompt to the user.
You can experiment with True to see what that does.

7. Now save the macro with a name called Autoexec.
With this name, this particular macro will fire any time this database is opened, unless of course
they hold down the shift key. (That can be disabled as well) If you have already created an Autoexec
macro just add this RunCode option at the bottom of any existing elements.

8. Make sure you set an application title under Tools | Startup | Application Title

9. Now save everything and close the database

10. Open the database, minimize, and then try and open another instance.
You should see some screen flickering, but only one instance in the Task Bar should show.

Hope that helps,
 

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