OLEDBError Object and the OLEDBErrors Collection Example

Sub CheckOLEDbErrors()

Dim oErr As OLEDBError

Dim sMsg As String

'Continue after errors

On Error Resume Next

'Don't show logon prompts etc

Application.DisplayAlerts = False

'Update an OLE DB pivot table

ActiveSheet.PivotTables(1).Refresh

'Any errors?

If Application.OLEDBErrors.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.OLEDBErrors

sMsg = sMsg & vbCrLf & oErr.ErrorString & "

(" & oErr.SqlState & ")"

Next

MsgBox sMsg

End If

End Sub

0 0

Post a comment