Log report

J

Justin

I have a question. I want to build a form/report where I can track everyone
that touch the database that I created. It can be in a form or a report
Just want to knwo what is the easiest way

How the users are logging in is by the network ID, if it isn't pre
registered already, then the user will not be able to log on.
 
K

Ken Sheridan

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.
 
Top