I have an error handler module with the code below that keeps breaking on the SQL statement in the LogError function with a runtime error of -2147217900(80040e14) Syntax Error (Missing Operator).... When I take out the ErrorString and str.Message portions of the code, I don't get the error. I got this code straight from a development book--can anyone help me understand how to get it to work with the Err.Description part?
Thanks!!!
tgikristi
Option Compare Database
Option Explicit
Const FormName2 = "basGenericErrorHandler"
'Type structure used to hold error information
Type typErrors
datDateTime As Variant
strUserName As String
lngErrorNum As Long
strMessage As String
strRoutine As String
strForm As String
End Type
------------------------------------------------
'Declaration of public type structure variable
Public gtypError As typErrors
'Constants used by global error handler
Public Const ERR_CONTINUE = 0 'Resume Next
Public Const ERR_RETRY = 1 'Resume
Public Const ERR_QUIT = 2 'End
Public Const ERR_EXIT = 3 'Exit Sub or Func
Function ErrorHandler(lngErrorNum As Long, _
strErrorDescription As String, _
strFormName As String, _
strRoutineName As String) As Integer
'Populate elements of the type structure variable
'with information about the error that occurred
gtypError.datDateTime = Now
gtypError.strUserName = CurrentUser()
gtypError.lngErrorNum = lngErrorNum
gtypError.strMessage = strErrorDescription
gtypError.strRoutine = strRoutineName
gtypError.strForm = strFormName
'Log the error
Call LogError
'Locate the error number in tblErrors to
'determine how you should respond to the error
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "Select Response from tblErrors Where ErrorNum = " & lngErrorNum, _
CurrentProject.Connection, adOpenStatic
'If the error number that occurred is not found
'in tblErrors, return ERR_QUIT to the problem routine
If rst.EOF Then
MsgBox "Error Number" & Err.Number & ": " & Err.Description
ErrorHandler = ERR_EXIT
'If the error is in tblErrors, evaluate the contents of
'the Response field. Respond appropriately, returning the appropriate value to the offending routine
Else
Select Case rst!Response
Case ERR_QUIT
MsgBox "Critical Error: Database will close." & vbCrLf & _
"Error Number" & Err.Number & ": " & Err.Description
ErrorHandler = ERR_QUIT
Case ERR_RETRY
ErrorHandler = ERR_RETRY
Case ERR_EXIT
MsgBox "Severe Error: Procedure could not complete." & vbCrLf & _
"Error Number" & Err.Number & ": " & Err.Description
ErrorHandler = ERR_EXIT
Case ERR_CONTINUE
ErrorHandler = ERR_CONTINUE
End Select
End If
End Function
--------------------------------------------------
Sub LogError()
'Declare a Connection object
Dim Cnn As ADODB.Connection
Dim strSQL As String
'Point the Connection object at the connection
'associated with the current project
Set Cnn = CurrentProject.Connection
'Build a SQL statement that inserts error information
'into the tblErrorLog table
strSQL = "INSERT INTO tblErrorLog ( ErrorDate, ErrorTime, UserName, ErrorNum, ErrorString, RoutineName, FormName) "
strSQL = strSQL & "Select #" & gtypError.datDateTime & "#, #" _
& gtypError.datDateTime & "#, '" _
& gtypError.strUserName & "', " _
& gtypError.lngErrorNum & ", '" _
& gtypError.strMessage & "', '" _
& gtypError.strRoutine & "', '" _
& gtypError.strForm & "'"
'Execute the SQL statement
Cnn.Execute strSQL, , adExecuteNoRecords
End Sub
Thanks!!!
tgikristi
Option Compare Database
Option Explicit
Const FormName2 = "basGenericErrorHandler"
'Type structure used to hold error information
Type typErrors
datDateTime As Variant
strUserName As String
lngErrorNum As Long
strMessage As String
strRoutine As String
strForm As String
End Type
------------------------------------------------
'Declaration of public type structure variable
Public gtypError As typErrors
'Constants used by global error handler
Public Const ERR_CONTINUE = 0 'Resume Next
Public Const ERR_RETRY = 1 'Resume
Public Const ERR_QUIT = 2 'End
Public Const ERR_EXIT = 3 'Exit Sub or Func
Function ErrorHandler(lngErrorNum As Long, _
strErrorDescription As String, _
strFormName As String, _
strRoutineName As String) As Integer
'Populate elements of the type structure variable
'with information about the error that occurred
gtypError.datDateTime = Now
gtypError.strUserName = CurrentUser()
gtypError.lngErrorNum = lngErrorNum
gtypError.strMessage = strErrorDescription
gtypError.strRoutine = strRoutineName
gtypError.strForm = strFormName
'Log the error
Call LogError
'Locate the error number in tblErrors to
'determine how you should respond to the error
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "Select Response from tblErrors Where ErrorNum = " & lngErrorNum, _
CurrentProject.Connection, adOpenStatic
'If the error number that occurred is not found
'in tblErrors, return ERR_QUIT to the problem routine
If rst.EOF Then
MsgBox "Error Number" & Err.Number & ": " & Err.Description
ErrorHandler = ERR_EXIT
'If the error is in tblErrors, evaluate the contents of
'the Response field. Respond appropriately, returning the appropriate value to the offending routine
Else
Select Case rst!Response
Case ERR_QUIT
MsgBox "Critical Error: Database will close." & vbCrLf & _
"Error Number" & Err.Number & ": " & Err.Description
ErrorHandler = ERR_QUIT
Case ERR_RETRY
ErrorHandler = ERR_RETRY
Case ERR_EXIT
MsgBox "Severe Error: Procedure could not complete." & vbCrLf & _
"Error Number" & Err.Number & ": " & Err.Description
ErrorHandler = ERR_EXIT
Case ERR_CONTINUE
ErrorHandler = ERR_CONTINUE
End Select
End If
End Function
--------------------------------------------------
Sub LogError()
'Declare a Connection object
Dim Cnn As ADODB.Connection
Dim strSQL As String
'Point the Connection object at the connection
'associated with the current project
Set Cnn = CurrentProject.Connection
'Build a SQL statement that inserts error information
'into the tblErrorLog table
strSQL = "INSERT INTO tblErrorLog ( ErrorDate, ErrorTime, UserName, ErrorNum, ErrorString, RoutineName, FormName) "
strSQL = strSQL & "Select #" & gtypError.datDateTime & "#, #" _
& gtypError.datDateTime & "#, '" _
& gtypError.strUserName & "', " _
& gtypError.lngErrorNum & ", '" _
& gtypError.strMessage & "', '" _
& gtypError.strRoutine & "', '" _
& gtypError.strForm & "'"
'Execute the SQL statement
Cnn.Execute strSQL, , adExecuteNoRecords
End Sub