How can I check if an Access database is open?

M

Mike L

I need to determine from one Access database whether another Access database
is open. How can I do this?
 
S

Stuart McCall

Mike L said:
I need to determine from one Access database whether another Access
database is open. How can I do this?

Look for the presence of a xxx.ldb file in the same folder as the database
file, where xxx is the same name as the database. If .ldb file is present,
the database is open. Use the Dir function.
 
M

Mike L

Thanks, Stuart. But if the target .mdb is terminated abnormally, the .ldb
may still exist. Is there another way, perhaps using the windows api?

I thought of having the target mdb write the system date/time to an internal
table every minute; link to this table and check if no update has occurred
within the past minute, which would indicate that the target mdb is not
executing. Hoping there is an easier way.
 
S

Stuart McCall

Mike L said:
Thanks, Stuart. But if the target .mdb is terminated abnormally, the .ldb
may still exist. Is there another way, perhaps using the windows api?

I thought of having the target mdb write the system date/time to an
internal table every minute; link to this table and check if no update has
occurred within the past minute, which would indicate that the target mdb
is not executing. Hoping there is an easier way.
<snip>

Ok. Try this:

Public Function dbOpen(dbFile As String) As Boolean
Dim fh As Integer

fh = FreeFile
On Error Resume Next
Open dbFile For Binary Access Read Write Shared As fh
dbOpen = (Err.Number > 0)
Close fh
End Function

If dbFile is open, it will be locked by the OS and the Open command will
fail.
 
M

Marshall Barton

Mike said:
I need to determine from one Access database whether another Access database
is open. How can I do this?


I think you can just try to use OpenDatabase with the
Exclusive Option.
 

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