Reading the Record Locking File

R

Ray

I have a database with a one Backend and identical copies of the Frontend
placed on the desktop of 12 different computers. I would like to monitor
which computers are accessing the Backend at any time and display that
information using a Form. I would like to "read" the Backend's Record Locking
File and get the computer names that are currently accessing it. (I dont want
to manually open the file in Notepad and read the names).

How can i get this Record Locking Information into a variable in VBA? OR How
can i use a Like statement to check for computer names in the file?
 
S

Stuart McCall

Ray said:
I have a database with a one Backend and identical copies of the Frontend
placed on the desktop of 12 different computers. I would like to monitor
which computers are accessing the Backend at any time and display that
information using a Form. I would like to "read" the Backend's Record
Locking
File and get the computer names that are currently accessing it. (I dont
want
to manually open the file in Notepad and read the names).

How can i get this Record Locking Information into a variable in VBA? OR
How
can i use a Like statement to check for computer names in the file?

You can use this code:

Public Function TestUsers()
t$ = DBUsers1("C:\Tests\Tests.mdb")
a = Split(t, ";")
For i = LBound(a) To UBound(a) Step 2
Debug.Print a(i), a(i + 1)
'machine name, login name
Next
End Function


Public Function DBUsers1(ByVal path As String) As String
path = Replace(path, ".mdb", ".ldb")
f% = FreeFile
Open path For Binary Access Read As f
Do Until EOF(f)
b$ = Space$(64)
Get #f, , b
If Asc(b) = 0 Then Exit Do
r$ = r$ & ";" & StripNull(Left$(b, 32))
r = r & ";" & StripNull(Right$(b, 32))
Loop
DBUsers1 = Mid$(r, 2)
End Function

Function StripNull(s$) As String
p& = InStr(1, s, vbNullChar)
If p = 0 Then Exit Function
StripNull = Left$(s, p - 1)
End Function

Set the path to your back end mdb in the "TestUsers" function and run it.
Output is to the debug window and takes the form:

machine name login name
 
S

Stuart McCall

One or two minor corrections. Use this code instead of that in my previous:

Public Function TestUsers()
t$ = DBUsers1("C:\Tests\Tests.mdb")
a = Split(t, ";")
For i = LBound(a) To UBound(a) Step 2
Debug.Print a(i), a(i + 1)
'machine name, login name
Next
End Function

Public Function DBUsers1(ByVal path As String) As String
path = Replace(path, ".mdb", ".ldb")
f% = FreeFile
Open path For Binary Access Read As f
Do Until EOF(f)
b$ = Space$(64)
Get #f, , b
If Asc(b) = 0 Then Exit Do
r$ = r$ & ";" & StripNull(Left$(b, 32))
r = r & ";" & StripNull(Right$(b, 32))
Loop
Close f
DBUsers1 = Mid$(r, 2)
End Function

Function StripNull(s$) As String
p& = InStr(1, s, vbNullChar)
If p = 0 Then
StripNull = s
Exit Function
End If
StripNull = Left$(s, p - 1)
End Function
 
B

Brian

When I try this approach I get:

"Compile Error: User-defined type not defined"

and the line "cn As New ADODB.Connection" highlighted in the code.

Am I doing something wrong?
 
D

Douglas J. Steele

Sounds as though you don't have a reference set to Microsoft ActiveX Data
Objects 2.n Library.
 

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