R
Rob Hofkens
Hello everyone
I have a problem with some code and I cannot find the problem
The code I use is from Allen Brown and its purpose it to log errors in a
table.
Here is the link to the original code
http://www.allenbrowne.com/ser-23a.html
I use Access as a Front End 2003 and SQL Server 2000 as Back End.
The table "tLogError" is linked via a DSNless connection.
I am able to add records directly into the table so I figure that all is
well with table itself.
When I use the original code I get an error about dbSeeChanges and I don't
know what to do about that?
It has something to do with the SQL Server Indentify column.
I tried to change the line:
Set rst = CurrentDb.OpenRecordset("tLogError", , dbAppendOnly)
to:
Set rst = CurrentDb.OpenRecordset("tLogError", , dbAppendOnly +
dbSeeChanges)
But that didnt work
So I modified the code to use ADO but the code doesn't add a record to the
table.
When I go through the code with trace, I see that the code that does this is
executed.
But when it is done I don't see a new record in the table?
So althoug the code is executed it doesn't work and there is no error mesage
or something that indicates that something is wrong.
Can someone help me plz ?
Here is my modified code to use ADO:
Function LogError(ByVal lngErrNumber As Long, ByVal strErrDescription As
String, _
strCallingProc As String, Optional vParameters, Optional bShowUser As
Boolean = True) As Boolean
' Author: Allen Browne, (e-mail address removed)
On Error GoTo Err_LogError
Dim strMsg, strSQL As String
Dim cn As ADODB.Connection
Dim rs As New ADODB.Recordset
Select Case lngErrNumber
Case 0
Debug.Print strCallingProc & " called error 0."
Case 2501 ' Cancelled
'Do nothing.
Case 3314, 2101, 2115 ' Can't save.
If bShowUser Then
strMsg = "Record cannot be saved at this time." & vbCrLf & _
"Complete the entry, or press <Esc> to undo."
MsgBox strMsg, vbExclamation, strCallingProc
End If
Case Else
If bShowUser Then
strMsg = "Error " & lngErrNumber & ": " & strErrDescription
MsgBox strMsg, vbExclamation, strCallingProc
End If
Set cn = CurrentProject.Connection
cn.BeginTrans
strSQL = "SELECT * FROM tLogError"
rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic
rs.AddNew
' Waarden toekennen aan de velden
rs![ErrNumber] = lngErrNumber
rs![ErrDescription] = Left$(strErrDescription, 255)
rs![ErrDate] = Now()
rs![CallingProc] = strCallingProc
rs![UserName] = CurrentUser()
rs![ShowUser] = bShowUser
If Not IsMissing(vParameters) Then
rs![Parameters] = Left(vParameters, 255)
End If
rs.Update
rs.Close
LogError = True
End Select
Exit_LogError:
Set rs = Nothing
Exit Function
Err_LogError:
strMsg = "An unexpected situation arose in your program." & vbCrLf & _
"Please write down the following details:" & vbCrLf & vbCrLf & _
"Calling Proc: " & strCallingProc & vbCrLf & _
"Error Number " & lngErrNumber & vbCrLf & strErrDescription & vbCrLf
& vbCrLf & _
"Unable to record because Error " & Err.Number & vbCrLf &
Err.Description
MsgBox strMsg, vbCritical, "LogError()"
Resume Exit_LogError
End Function
I have a problem with some code and I cannot find the problem
The code I use is from Allen Brown and its purpose it to log errors in a
table.
Here is the link to the original code
http://www.allenbrowne.com/ser-23a.html
I use Access as a Front End 2003 and SQL Server 2000 as Back End.
The table "tLogError" is linked via a DSNless connection.
I am able to add records directly into the table so I figure that all is
well with table itself.
When I use the original code I get an error about dbSeeChanges and I don't
know what to do about that?
It has something to do with the SQL Server Indentify column.
I tried to change the line:
Set rst = CurrentDb.OpenRecordset("tLogError", , dbAppendOnly)
to:
Set rst = CurrentDb.OpenRecordset("tLogError", , dbAppendOnly +
dbSeeChanges)
But that didnt work
So I modified the code to use ADO but the code doesn't add a record to the
table.
When I go through the code with trace, I see that the code that does this is
executed.
But when it is done I don't see a new record in the table?
So althoug the code is executed it doesn't work and there is no error mesage
or something that indicates that something is wrong.
Can someone help me plz ?
Here is my modified code to use ADO:
Function LogError(ByVal lngErrNumber As Long, ByVal strErrDescription As
String, _
strCallingProc As String, Optional vParameters, Optional bShowUser As
Boolean = True) As Boolean
' Author: Allen Browne, (e-mail address removed)
On Error GoTo Err_LogError
Dim strMsg, strSQL As String
Dim cn As ADODB.Connection
Dim rs As New ADODB.Recordset
Select Case lngErrNumber
Case 0
Debug.Print strCallingProc & " called error 0."
Case 2501 ' Cancelled
'Do nothing.
Case 3314, 2101, 2115 ' Can't save.
If bShowUser Then
strMsg = "Record cannot be saved at this time." & vbCrLf & _
"Complete the entry, or press <Esc> to undo."
MsgBox strMsg, vbExclamation, strCallingProc
End If
Case Else
If bShowUser Then
strMsg = "Error " & lngErrNumber & ": " & strErrDescription
MsgBox strMsg, vbExclamation, strCallingProc
End If
Set cn = CurrentProject.Connection
cn.BeginTrans
strSQL = "SELECT * FROM tLogError"
rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic
rs.AddNew
' Waarden toekennen aan de velden
rs![ErrNumber] = lngErrNumber
rs![ErrDescription] = Left$(strErrDescription, 255)
rs![ErrDate] = Now()
rs![CallingProc] = strCallingProc
rs![UserName] = CurrentUser()
rs![ShowUser] = bShowUser
If Not IsMissing(vParameters) Then
rs![Parameters] = Left(vParameters, 255)
End If
rs.Update
rs.Close
LogError = True
End Select
Exit_LogError:
Set rs = Nothing
Exit Function
Err_LogError:
strMsg = "An unexpected situation arose in your program." & vbCrLf & _
"Please write down the following details:" & vbCrLf & vbCrLf & _
"Calling Proc: " & strCallingProc & vbCrLf & _
"Error Number " & lngErrNumber & vbCrLf & strErrDescription & vbCrLf
& vbCrLf & _
"Unable to record because Error " & Err.Number & vbCrLf &
Err.Description
MsgBox strMsg, vbCritical, "LogError()"
Resume Exit_LogError
End Function