How do I check to see if an Access Database is locked using VBA?

  • Thread starter Thread starter Dick
  • Start date Start date
D

Dick

I am trying to find out if a database is locked (Open) before I run a macro
to compress it. If the file is locked I want to quit running the macro.

Thanks,
 
Here is one way: look for the file with the same name as your back end .mdb
or .mdb, but with the .ldb extension, in the same folder as the back end
..mdb/.mde.

Dim FileName as String
FileName = "R:\MyPath\MyDB.ldb" 'full path & filename of expected .ldb file
If Len(Dir(FileName) = 0 Then 'will be 0 if the file does not exist
'run your code here
End If

One of the MVP's probably has a better answer than mine, though.
 
Back
Top