Access – Check If Anyone Has The Database Open

How can we tell if someone else has the database open?
 

Check for the Existence of a Lock File

In most cases, we should be able to check for the existence of a lock file (ldb or laccdb file). To do so we can use a function like the one presented in my article:

 

Now, in most scenarios, like 95+% of the time checking for the presence of a lock file is sufficient.  However, there is one scenario where a lock file will not be present and that is when someone already has it opened exclusively.

If a user opens a database with exclusive access (by clicking the arrow to the right of the Open button, and then clicking Open Exclusive), record locking is not used. Therefore, Microsoft Access doesn’t attempt to open or create a lock file. Microsoft

Therefore, looking for a lock file will not detect those instances when someone has the database open in Exclusive mode.

The instant you go to open a database file, that is already opened exclusively, you will receive an error message:

Could not use ‘FilePathAndName’; file already in use.

 

A Better Solution

So what else can we do to validate if the database is being used by anyone if looking for a lock file isn’t 100% reliable?  What if we want to validate this through automation?

Actually, the solution is quite simple. We can check if the file is being used by trying to lock it.  To do so we can use the File_IsOpen function from my article:

this function will work in all instances: opened normally, opened exclusively.  So it is more reliable than just checking for the presence of a lock file, if you want to be 100% safe.

Note, the function is also 100% compatible with VBScript.

Another option would be to try to connect to the database via automation and trap the ensuing error. That said, I have experienced very mix results attempting this and NOT always getting an error reported back! As such, I personally find the File_IsOpen simpler and more reliable at this point in time.
 

Useful Resources