User Login tracking

ChrisB37

Registered User.
Local time
Today, 14:22
Joined
Nov 26, 2004
Messages
28
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.
 
at a guess

Dim strUserName As String, db As dao.Database, r As dao.Recordset, rst As dao.Recordset

You will need to make sure there is a reference to DAO in Tools>references... in any module

Peter
 
Thanks,

But I am not sure how to set up the DAO reference. I am sure this is not set-up because I tried to implement another module earlier and the debugger flagged the DAO reference.

Could you help me in setting this up?

CB
 
Ok,
I figured out the DAO reference by doing a search. Got that part fixed. Now, can anyone help me understand how to set this code up to work on loading my switchboard?

I set it up, I thought like the instructions said to, but it doesn't dump anything into the table and it flags an error.

On setting this onload event I went into the Event Procedure and this is how it is set up:

Private Sub Form_Load()
Call FosUserName
End Sub

Now in debugging it gives me this error:
Compile error: Expected variable or procedure, not module.

Any ideas???

Thanks,
CB
 
Two things, make sure you did not save the module as FosUserName or you will confuse access

I don't think you need 'call'

Private Sub Form_Load()
FosUserName
End Sub

HTH

Peter
 
The Environ function is a lot easier to work with...

Msgbox Environ("UserName")
Msgbox Environ("ComputerName")
 
Thanks a bunch.

I now have this working. I just have to work out the update query to log in the sign-out times.

Appreciate everything.

Thanks

CB :)
 

Users who are viewing this thread

Back
Top Bottom