You can get the logged in user with a call to the Windows API. Put the
following module in your database:
'module starts'
Option Compare Database
Option Explicit
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal _
lpBuffer As String, nSize As Long) As Long
Public Function GetUser() As String
Dim strBuffer As String
Dim lngSize As Long, lngRetVal As Long
lngSize = 199
strBuffer = String$(200, 0)
lngRetVal = GetUserName(strBuffer, lngSize)
GetUser = Left$(strBuffer, lngSize - 1)
End Function
'module ends'
Create a table UserLog with fields UserName (text) and WhenUsed (date/time).
Call the following code when the database is opened. You could do this in
the Open event procedure of the database's opening form (e.g. a switchboard)
or in a function called by an autoexec macro:
Dim cmd As ADODB.Command
Dim strSQL As String
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
cmd.CommandText = strSQL
strSQL = "INSERT INTO UserLog(UserName,WhenUsed) " & _
"VALUES(""" & GetUser() & """,#" & _
Format(Now(), "mm/dd/yyyy hh:nn:ss") & "#)"
cmd.CommandText = strSQL
cmd.Execute
This would log whoever opens the database and when they do so. Put the
UserLog table in the back end on the server and the code in each front end on
the workstations. You can base a form or report on the table.