Question Open the same .mde file on a computer only one time.

TJBernard

Registered User.
Local time
Today, 15:13
Joined
Mar 28, 2002
Messages
176
I found this nice code that prevents a user from opening a .mde file on a computer more than one time. I was shocked to find out that a .mde file can be opened more than one time on a single machine.

Unfortunately if the file is opened using MS Access 2007, it can be opened more than one time. So the problem returns as our company upgrades from MS Access 2003 to MS Access 2007 (ugh, 2007 has been such a headache).

I have attached the code module below that works just fine in MS Access 2003, but not in 2007. When the form that is defaulted as the start-up form opens up, this code module is run on the Open Event. If anyone has any ideas of what I can do to make it work in MS Access 2007, let me know.

Thank you for your help.

T.J.
 

Attachments

why can't you just put a table in your database with one field in it? make it a boolean. on first open, record something that identifies the computer, then everytime it is opened, check for that identifier in that field on the table. if the identifier is there, shut it down----if it is not there, record it. i.e. - if DCOUNT() > 0, then shut down, else record it and open the form.


by the way, a better way I think to do this I think would be to put a docmd.openform with the opening code and drop the formname in the access options. if you have any kind of code that runs on the open of a database, this is better, so you don't have to keep changing code behind forms, but rather one line in the same procedure.
 
Last edited:
what is the problem with opening it more than once?

that is what a multi-user environment does?

the problem with most schemes to stop it opening more than once, by writing to a table (or even the registry) is that if the app crashes, you will HAVE to give users the option of entering an apparently locked/in use system (eg thats what Sage does)
 
why can't you just put a table in your database with one field in it? make it a boolean. on first open, record something that identifies the computer, then everytime it is opened, check for that identifier in that field on the table. if the identifier is there, shut it down----if it is not there, record it. i.e. - if DCOUNT() > 0, then shut down, else record it and open the form.


by the way, a better way I think to do this I think would be to put a docmd.openform with the opening code and drop the formname in the access options. if you have any kind of code that runs on the open of a database, this is better, so you don't have to keep changing code behind forms, but rather one line in the same procedure.

These are some GREAT ideas, and I do believe this would work for me.

On the database open, check to see if there is the computer name in a table list. If there is not, add the computer name to the table, and set a boolean field to true.

If the computer name is in the table and the boolean value is true, then quit the application of opening up the .mde file.

On the close of the .mde file, reset the boolean field to false.

I have a few questions regarding this...

#1) Is there a way to set up a code module to run on the close of the database (so the boolean field is set back to false)? Is there a property or event that is triggered when the database is closed?

#2) Is it possible to track a computer (machine) name? Some of my users have two or even three computers, so it would be okay if they open the same .mde file on two different machines (incase they don't close out on their desk top, and then on the go they log in on their lap top).

If not, this is fine, I will go by Environ("username") and just capture the username associated with the user. And they will need to learn that they have to close the database on all computers.

Let me know.

And thank you for your help.

T.J.
 

Users who are viewing this thread

Back
Top Bottom