Locked Database ?

  • Thread starter Nikos Yannacopoulos
  • Start date
N

Nikos Yannacopoulos

I have faced the same issue, and dealt with it by checking
the .ldb file.
In the folder where your database file resides (let's call
it dbname.mdb for this example), every time a user opens
it you will see a temporary file called dbname.ldb which
goes away when the last user closes the database. In this
file there is an entry for every running instance of the
database, the first field of which is the name of the
computer running the instance. I have noticed that between
consecutive entries there are two strings of consecutive
spaces (ASCII 32), so what I do is I check the number of
those strings, and if it is not greater than 2 I know I am
the only user. I do this through the following piece of
code:

Dim db As Database
Set db = CurrentDb()

dbldb = Left(db.Name, Len(db.Name) - 3) & "ldb"

On Error Resume Next
Close #1

Open dbldb For Input As #1

x = 0
y = 0

Do Until EOF(1)
t = Input(1, #1)
If Asc(t) = 32 Then
If y = 0 Then
x = x + 1
y = 1
End If
Else
y = 0
End If
Loop
Close #1

If x <= 2 Then
RUN MY CODE
End If

There might be a smarter way to do it, but this one works
fine. I hope this helps.

Nikos Y.
 
J

JohnV

I found this Knowledge Base Article - #186304:
http://support.microsoft.com/default.aspx?scid=kb;en-
us;186304&Product=vba

It requires the use of MDSLDBUSR.DLL which can be found in
the Jet Utilities download. Company policy restricts
downloading from web sites during prime work hours so I
have not had a chance to test it out or modify the
function just to return the count of users. It does look
to be a little more efficeint, but it requires that the
dll be installed on every machine that is going to use it.

Regards,
JohnV
 
N

Nikos Yannacopoulos

#1 is the VB reference to the file opened (if you neede
more files open at the sime they would be assigned
references #2, #3 etc.). This becomes clear if you read
further down through the code.

The reason why Close #1 is at the beginning is just in
case a file is left open by some other process, which
would produce an error. That's why it is preceded by On
Error Resume Next, so it's ignored if no file is open as
#1.

Nikos Y.
 

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