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.
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.