ODBCError Properties

Name

Returns

Description

ErrorString

String

Read-only. Returns the error string generated from the ODBC connection

SqlState

String

Read-only. Returns the SQL state error generated from the ODBC connection

ODBCError Object and the ODBCErrors Collection Example

Sub CheckODBCErrors() Dim oErr As ODBCError Dim sMsg As String 'Continue after errors On Error Resume Next 'Don't show logon prompts etc Application.DisplayAlerts = False 'Update an ODBC query table ActiveSheet.QueryTables(1).Refresh 'Any errors?

If Application.ODBCErrors.Count = 0 Then 'No, so all OK MsgBox "Updated OK"

Sub CheckODBCErrors() Dim oErr As ODBCError Dim sMsg As String 'Continue after errors On Error Resume Next 'Don't show logon prompts etc Application.DisplayAlerts = False 'Update an ODBC query table ActiveSheet.QueryTables(1).Refresh 'Any errors?

If Application.ODBCErrors.Count = 0 Then 'No, so all OK MsgBox "Updated OK"

Else

'Yes, so list them all sMsg = "The following error(s) occurred during the update" For Each oErr In Application.ODBCErrors sMsg = sMsg & vbCrLf & oErr.ErrorString & " (" & oErr.SqlState & ")" Next

MsgBox sMsg End If End Sub

0 0

Post a comment