cbjames said:
I am looking for some code to place in all of my reports that will write
three values to the table [Report_Access] when a reports is open.
(1) User (2) Now() and (3) The Report Opened. This way we can
track the "who,what and when" of our reports. Any help would be
greatly appreciated. Thanks.
Public Function LogDoc(obj As Object)
On Error GoTo Err_Handler
'Purpose: Track who opened forms/reports when.
'Author: Allen Browne
http://allenbrowne.com
'Release: Feb 2009.
'Variation: To log the Windows user instead of JET user, see:
'
http://www.mvps.org/access/api/api0008.htm
'Usage: Set the On Load property of your forms:
' =LogDoc([Form]
' or for reports:
' =LogDoc([Report]
' Alternatively, in code (event procedure) use:
' Call LogDoc(Me)
'Assumes: Table named tblLogDoc, with fields:
' LogDocID AutoNumber Primary key
' DocName Text (64) name of form/report
' DocTypeID Number (Long) 2=form, 3=report
' DocUser Text (64) who opened it
' DocDateTime Date/Time when they opened it.
Dim strSql As String
Dim lngObjType As Long
Dim strUser As String
strUser = CurrentUser()
If TypeOf obj Is Form Then
lngObjType = acForm
ElseIf TypeOf obj Is Report Then
lngObjType = acReport
End If
strSql = "INSERT INTO tblLogDoc ( DocName, DocTypeID, DocUser,
DocDateTime ) " & _
"SELECT """ & obj.Name & """ AS DocName, " & lngObjType & " AS
DocTypeID, """ & _
strUser & """ AS DocUser, Now() AS DocDateTime;"
DBEngine(0)(0).Execute strSql, dbFailOnError
Exit_Handler:
Exit Function
Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_Handler
End Function