Option Compare Database
Option Explicit
Private Const gstrObject = "basErrorLog"
Private strError As String
Public Function fnCreate_t99_Error_Log()
'//////////////////////////////////////////////////////////////////
'// Function: fnLog_Error
'//////////////////////////////////////////////////////////////////
'// Author: Tranchemontaigne
'//////////////////////////////////////////////////////////////////
'// Modified:
'// Date Editor Description
'// ----------------------------------------------------------
'// 21 Jan 2016 Tranchemontaigne -Created
'//
'//////////////////////////////////////////////////////////////////
'// Description:
'// Creates table used by this module
'//
'//////////////////////////////////////////////////////////////////
'// Requirements:
'// Microsoft Visual Basic for Applications
'// Microsoft Access 9.0 Object Library
'//
'//////////////////////////////////////////////////////////////////
Dim strSQL As String
strSQL = "CREATE TABLE"
strSQL = strSQL & " "
strSQL = strSQL & "t99_Error_Log"
strSQL = strSQL & " "
strSQL = strSQL & "("
strSQL = strSQL & " "
strSQL = strSQL & " t99_Error_ID COUNTER PRIMARY KEY"
strSQL = strSQL & ", t99_Time DATETIME"
strSQL = strSQL & ", t99_Login TEXT(50)"
strSQL = strSQL & ", t99_Object TEXT(50)"
strSQL = strSQL & ", t99_Code TEXT(255)"
strSQL = strSQL & ", t99_Message MEMO"
strSQL = strSQL & " "
strSQL = strSQL & ")"
Call fnRunSQL(strSQL)
End Function
Public Function fnLogError(gstrObject As String, gstrCode As String, _
gstrMessage As String)
'//////////////////////////////////////////////////////////////////
'// Function: fnLogError
'//////////////////////////////////////////////////////////////////
'// Author: Tranchemontaigne
'//////////////////////////////////////////////////////////////////
'// Modified:
'// Date Editor Description
'// ----------------------------------------------------------
'// 07 Mar 2013 Tranchemontaigne -Improved documentation
'//
'//////////////////////////////////////////////////////////////////
'// Description:
'// If a function, procedure, or subroutine produces an error
'// record the error in an error log table
'//
'//////////////////////////////////////////////////////////////////
'// Input:
'// Variable Description
'// ===========================================================
'// gstrObject Module object producing the error
'// gstrCode Code block within module producing error
'// gstrMessage Error message
'//
'//////////////////////////////////////////////////////////////////
'// Requirements:
'// Microsoft Visual Basic for Applications
'// Microsoft Access 9.0 Object Library
'// fnGet_UserID (Windows API module)
'//
'//////////////////////////////////////////////////////////////////
On Error GoTo Err_fnLogError
Dim gstrlogin As String
Dim gdtTime As Date
Dim gstrINSERT As String
Dim gstrVALUES As String
Dim gstrSQL As String
gstrlogin = ""
gdtTime = #1/1/1900#
gstrINSERT = ""
gstrVALUES = ""
gstrSQL = ""
gstrlogin = fnGet_UserID
gdtTime = Now()
gstrINSERT = "INSERT INTO t99_Error_Log( [t99_Time], [t99_Login], [t99_Object], [t99_Code], [t99_Message] )"
gstrVALUES = "VALUES (" & Chr(34) & gdtTime & Chr(34) & ", " & Chr(34) & _
gstrlogin & Chr(34) & ", " & Chr(34) & gstrObject & Chr(34) & ", " & Chr(34) & _
gstrCode & Chr(34) & ", " & Chr(34) & gstrMessage & Chr(34) & " );"
gstrSQL = gstrINSERT & " " & gstrVALUES
With DoCmd
.SetWarnings False
.RunSQL gstrSQL
.SetWarnings True
End With
Exit_fnLogError:
Exit Function
Err_fnLogError:
strError = "ARGUMENTS: " & Chr(10) & Chr(13) & _
" gstrObject: " & gstrObject & _
Chr(10) & Chr(13) & _
" gstrCode: " & gstrCode & _
Chr(10) & Chr(13) & _
" gstrlogin: " & gstrlogin & _
Chr(10) & Chr(13) & _
Chr(10) & Chr(13) & _
"INTERNAL VARIABLES: " & _
" gstrMessage: " & gstrMessage & _
Chr(10) & Chr(13) & _
" gdtTime: " & gdtTime & _
Chr(10) & Chr(13) & _
" gstrINSERT: " & gstrINSERT & _
Chr(10) & Chr(13) & _
" gstrVALUES: " & gstrVALUES & _
Chr(10) & Chr(13) & _
Chr(10) & Chr(13) & _
" gstrSQL: " & gstrSQL & _
Chr(10) & Chr(13) & _
Chr(10) & Chr(13) & _
"ERROR " & _
" " & Err.Number & ": " & Err.Description
Debug.Print strError
MsgBox strError, vbCritical, "fnLogError encountered an error"
Resume Exit_fnLogError
End Function
Public Function fnRecordLogin()
'//////////////////////////////////////////////////////////////////
'// Function: fnLogError
'//////////////////////////////////////////////////////////////////
'// Author: Tranchemontaigne
'//////////////////////////////////////////////////////////////////
'// Modified:
'// Date Editor Description
'// ----------------------------------------------------------
'// 07 Mar 2013 Tranchemontaigne -Improved documentation
'//
'//////////////////////////////////////////////////////////////////
'// Description:
'// Records login ID in use when the database is opened
'//
'//////////////////////////////////////////////////////////////////
'// Input:
'// Variable Description
'// ===========================================================
'// gstrMessage Windows User ID
'//
'//////////////////////////////////////////////////////////////////
'// Requirements:
'// Microsoft Visual Basic for Applications
'// Microsoft Access 9.0 Object Library
'// fnGet_UserID (Windows API module)
'// fnLogError (ErrorLog module)
'//
'//////////////////////////////////////////////////////////////////
On Error GoTo Err_fnRecordLogin
Dim gstrlogin As String
Dim gdtTime As Date
Dim gstrINSERT As String
Dim gstrVALUES As String
Dim gstrSQL As String
Dim gstrMessage As String
gstrlogin = fnGet_UserID
gdtTime = Now()
gstrMessage = "login"
gstrINSERT = "INSERT INTO t99_Error_Log( [t99_Time], [t99_Login], [t99_Message] )"
gstrVALUES = "VALUES (" & Chr(34) & gdtTime & Chr(34) & ", " & Chr(34) & _
gstrlogin & Chr(34) & ", " & Chr(34) & gstrMessage & Chr(34) & ");"
gstrSQL = gstrINSERT & " " & gstrVALUES
With DoCmd
.SetWarnings False
.RunSQL gstrSQL
.SetWarnings True
End With
Exit_fnRecordLogin:
Exit Function
Err_fnRecordLogin:
Debug.Print gstrSQL
strError = "Error: " & Chr(10) & Chr(13) & _
" " & Err.Number & ": " & Err.Description
MsgBox strError, vbCritical, "Error: cmdNetworkPath_Click"
Call fnLogError(gstrObject, "cmdNetworkPath_Click", strError)
Resume Exit_fnRecordLogin
End Function
Public Function fnRecordLogout()
'//////////////////////////////////////////////////////////////////
'// Function: fnLogError
'//////////////////////////////////////////////////////////////////
'// Author: Chris Taylor
'//////////////////////////////////////////////////////////////////
'// Modified:
'// Date Editor Description
'// ----------------------------------------------------------
'// 18 Jul 2013 Tranchemontaigne -Created
'//
'//////////////////////////////////////////////////////////////////
'// Description:
'// Records user log out when the database is closed
'//
'//////////////////////////////////////////////////////////////////
'// Requirements:
'// Microsoft Visual Basic for Applications
'// Microsoft Access 9.0 Object Library
'// fnGet_UserID (Windows API module)
'// fnLogError (ErrorLog module)
'//
'//////////////////////////////////////////////////////////////////
On Error GoTo Err_fnRecordLogout
Dim gstrlogin As String
Dim gdtTime As Date
Dim gstrINSERT As String
Dim gstrVALUES As String
Dim gstrSQL As String
Dim gstrMessage As String
gstrlogin = fnGet_UserID
gdtTime = Now()
gstrMessage = "logout"
gstrINSERT = "INSERT INTO t99_Error_Log( [t99_Time], [t99_Login], [t99_Message] )"
gstrVALUES = "VALUES (" & Chr(34) & gdtTime & Chr(34) & ", " & Chr(34) & _
gstrlogin & Chr(34) & ", " & Chr(34) & gstrMessage & Chr(34) & ");"
gstrSQL = gstrINSERT & " " & gstrVALUES
With DoCmd
.SetWarnings False
.RunSQL gstrSQL
.SetWarnings True
End With
Exit_fnRecordLogout:
Exit Function
Err_fnRecordLogout:
Debug.Print gstrSQL
strError = "Error: " & Chr(10) & Chr(13) & _
" " & Err.Number & ": " & Err.Description
MsgBox strError, vbCritical, "Error: fnRecordLogout"
Call fnLogError(gstrObject, "fnRecordLogout", strError)
Resume Exit_fnRecordLogout
End Function