-
Jul 8th, 2008, 02:12 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] ODBC Error Trapping
Is there anyway to capture an ODBC error and manage it through an error handler?
I am using Access 2000 VBA
Swoozie
Somedays you just should not get out of bed.
-
Jul 9th, 2008, 07:12 AM
#2
Re: ODBC Error Trapping
VBA does support On Error GoTo, so that would be the way to trap the error.
-
Jul 11th, 2008, 05:51 AM
#3
Re: ODBC Error Trapping
i am not sure if this is what you are looking for
vb Code:
Public Function GetADO_Error() As String Dim i As Integer Dim sQuery As String Dim nNativeError As Long Dim ADORecordset As ADODB.Recordset GetADO_Error = "" If (m_ADOConnection.Errors.Count = 0) Then Exit Function 'Search for "*** ODBC" errors only, if there are no *** OBC errors then search for system errors For i = 0 To m_ADOConnection.Errors.Count - 1 If (InStr(m_ADOConnection.Errors(i).Description, "Transaction rollback") > 0) Then nNativeError = m_ADOConnection.Errors(i).NativeError Exit For End If Next i If ((nNativeError >= 10000) And (nNativeError < 20000)) Then 'Error GetADO_Error = "Error: " & Trim(Str(nNativeError)) nNativeError = nNativeError - 10000 sQuery = "Select Description from ImportErrors where ImportErrorID = " & Trim(Str(nNativeError)) ElseIf ((nNativeError >= 1) And (nNativeError < 10000)) Then 'Warning sQuery = "Select Description from ImportWarnings where ImportWarningID = " & Trim(Str(nNativeError)) GetADO_Error = "Warning: " & Trim(Str(nNativeError)) ElseIf (nNativeError >= 20000) Then sQuery = "Select Description from InternalODBCErrors where NativeErrorNumber = '" & Trim(Str(nNativeError) & "'") GetADO_Error = Trim(Str(nNativeError)) Else GetADO_Error = Err.Description Exit Function End If Set ADORecordset = m_ADOConnection.Execute(sQuery) GetADO_Error = GetADO_Error & " - " & ADORecordset.Fields("Description").Value ADORecordset.Close End Function
for this to work you have to declare the connection with events like
vb Code:
Private WithEvents m_ADOConnection As ADODB.Connection
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 23rd, 2008, 02:10 PM
#4
Thread Starter
Hyperactive Member
Re: ODBC Error Trapping
For some reason VBA did not capture the err when receiving and ODBC call fail, I had to use dbengine.err to identify the error and set a work around/response for when it happens.
Swoozie
Somedays you just should not get out of bed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|