Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90251

How to get SQL Query Error Details when QueryTable.Refresh fails

$
0
0

Say I have this simple bit of VBA that refreshes a query table:

With aListObject.QueryTable
    .refresh BackgroundQuery:=False
End With

If the above table returns an error from the SQL engine upon refreshing, then how do I obtain the actual SQL error details?

E.g. I want this type of message, which is returned in SQL Server Management Studio:

Msg 8134, Level 16, State 1, Line 1
Divide by zero error encountered.

I can add error handling to the VBA to return the VBA error as such:

On Error Resume Next    
With aListObject.QueryTable
    .refresh BackgroundQuery:=False
    if err.number > 0 then msgbox err.Description
End With
On Error GoTo 0

But this only returns this message:

SQL Syntax Error

How do I return the full SQL error message details?

I have looked at the QueryTable object (https://docs.microsoft.com/en-us/office/vba/api/excel.querytable) and the QueryTable.Refresh method (https://docs.microsoft.com/en-us/office/vba/api/excel.querytable.refresh) but can't find anything that jumps out there.


Viewing all articles
Browse latest Browse all 90251

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>