HI,
I performed a search to find some code to track when a user logs in and out of the database. This is what I have been able to find. The problem with it is when I try and run the code the debugger comes up and has a problem with the Line:
Dim strUserName As String, db As Database, r As Recordset, rst As Recordset
the db As Database flags.
Can anyone please help to debug this code or point me in the right direction to log this information. I would prefer not to have to create a form to log into.
Thanks,
CB
First create a table with these fields; Call it LogInTable
UserName
LogInDate
LogInTime
LogOutTime
Then copy this code and paste it into a new module exactly as it is.
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String, db As Database, r As Recordset, rst As Recordset
Dim table2 As String
Set db = CurrentDb
Set r = db.OpenRecordset("LogInTable")
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
r.MoveLast
r.AddNew
r.Fields("UserName") = UCase(fOSUserName)
r.Fields("LogInDate") = Date
r.Fields("LogInTime") = Time
r.Update
End Function
Then OnLoad of the switchboard - Call FosUserName()
The data will then be posted to the table when the user logs in.
I performed a search to find some code to track when a user logs in and out of the database. This is what I have been able to find. The problem with it is when I try and run the code the debugger comes up and has a problem with the Line:
Dim strUserName As String, db As Database, r As Recordset, rst As Recordset
the db As Database flags.
Can anyone please help to debug this code or point me in the right direction to log this information. I would prefer not to have to create a form to log into.
Thanks,
CB
First create a table with these fields; Call it LogInTable
UserName
LogInDate
LogInTime
LogOutTime
Then copy this code and paste it into a new module exactly as it is.
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String, db As Database, r As Recordset, rst As Recordset
Dim table2 As String
Set db = CurrentDb
Set r = db.OpenRecordset("LogInTable")
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
r.MoveLast
r.AddNew
r.Fields("UserName") = UCase(fOSUserName)
r.Fields("LogInDate") = Date
r.Fields("LogInTime") = Time
r.Update
End Function
Then OnLoad of the switchboard - Call FosUserName()
The data will then be posted to the table when the user logs in.