User Log for Access 2010 (1 Viewer)

eMel

Registered User.
Local time
Today, 02:12
Joined
Jun 23, 2014
Messages
62
I am trying to create a VB module that will log the time someone opens or closes an item in Access 2010. I want the times, user, and form/report/table name of whatever they used and it should be written to a table. The date/time works. Rather than my username being written to the table, it displays on a popup with a textbox under it asking for parameters.. I want my user to write to the table. Here's the code. Suggestions?
'Dimension a public variable at the top of the module.
Public LogEvent As String


'Public LogEvt As String

'******************** Code Start **************************
'
Private Declare PtrSafe 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
strUserName = String$(49, 0)
lngLen = 50
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
'******************** Code End **************************

Public Function LogEvt()
Dim SQL As String
SQL = "INSERT INTO EventLog ( Event, EvTime, UserName ) SELECT '" & LogEvent & "' AS x1, #" & Now() & "# as x2, " & fOSUserName() & ";"
DoCmd.RunSQL SQL
End Function
 
Last edited:

Users who are viewing this thread

Top Bottom