Who is logged in??????

Emmanuel

Master Tech
Local time
Today, 10:52
Joined
Sep 4, 2002
Messages
88
Hello people,

I have a need to detect who is using my data base at a specific time and better yet if I could keep a log of it. This is what I have lerned from you Access experts so far and let me tell you this is brilliant. This is a code that I found on this site and I am experiencing some problems with it.

Code......

Option Compare Database
' Declare a record type to break down the user info
Private Type UserRec
bMach(1 To 32) As Byte ' 1st 32 bytes hold machine name
bUser(1 To 32) As Byte ' 2nd 32 bytes hold user name
End Type

Private Sub Form_Open(Cancel As Integer)

Me.LoggedOn.RowSource = WhosOn()

End Sub

Private Sub UpdateBtn_Click()

Me.LoggedOn.RowSource = WhosOn()

End Sub

'---------------------------------------------
' Subject : WhosOn()
' Purpose : Will read *.LDB file and read who's currently
' logged on and their station name.
'
' The LDB file has a 64 byte record.
'
' The station name starts at byte 1 and is null
' terminated.
'
' Log-in names start at the 33rd byte and are
' also null terminated.
'
' I had to change the way the file was accessed
' because the Input() function did not return
' nulls, so there was no way to see where the
' names ended.
'---------------------------------------------
Private Function WhosOn() As String

On Error GoTo Err_WhosOn

Dim iLDBFile As Integer, iStart As Integer
Dim iLOF As Integer, i As Integer
Dim sPath As String, X As String
Dim sLogStr As String, sLogins As String
Dim sMach As String, sUser As String
Dim rUser As UserRec ' Defined in General
Dim dbCurrent As Database

' Get Path of current database. Should substitute this code
' for an attached table path in a multi-user environment.

Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
sPath = dbCurrent.Name
dbCurrent.Close

' Iterate thru dbCurrent.LDB file for login names.

sPath = Left(sPath, InStr(1, sPath, ".")) + "LDB"

' Test for valid file, else Error

X = dir(sPath)
iStart = 1
iLDBFile = FreeFile

Open sPath For Binary Access Read Shared As iLDBFile
iLOF = LOF(iLDBFile)
Do While Not EOF(iLDBFile)
Get iLDBFile, , rUser
With rUser
i = 1
sMach = ""
While .bMach(i) <> 0
sMach = sMach & Chr(.bMach(i))
i = i + 1
Wend
i = 1
sUser = ""
While .bUser(i) <> 0
sUser = sUser & Chr(.bUser(i))
i = i + 1
Wend
End With
sLogStr = sMach & " -- " & sUser
If InStr(sLogins, sLogStr) = 0 Then
sLogins = sLogins & sLogStr & ";"
End If
iStart = iStart + 64 'increment to next record offset
Loop
Close iLDBFile
WhosOn = sLogins

Exit_WhosOn:
Exit Function

Err_WhosOn:
If err = 68 Then
MsgBox "Couldn't populate the list", 48, "No LDB File"
Else
MsgBox "Error: " & err.Number & vbCrLf & err.Description
Close iLDBFile
End If
Resume Exit_WhosOn

End Function


The thing is that I have some errors on it like for example on the following example it showed a "Method or data member not found":

Private Sub Form_Open(Cancel As Integer)

Me.LoggedOn.RowSource = WhosOn()

End Sub

Could someone help me? Please?


Best Regards,
Emmanuel Roque
 
Thanks

Dear Chewy,

Thanks for your data base but I don't seam to understand what to do.. I tried copying the frm1 to my data base to use it but it actualy gave me an error and closed the data base.


Can you help? I am using Access xp or 2002 if that helps..

Best Regards,
Emmanuel Roque
 
i just pmed you send me your database
 
i was able to make a new form that it works for. But am still looking to get it in your current one
 

Users who are viewing this thread

Back
Top Bottom