Excel VBA How to detect that SQL query returned no data?
Posted on 2011-09-02
I have Excel VBA code that calls a SQL Server 2008 stored proc, and all is fine when the user supplies a valid parameter. How can I tell in VBA when the user supplies a bad account number and there is no data returned from SQL Server to Excel?
I know how to check for EOF on the returned data with ADO, but this project is using OLEDB.
'Execute stored procedure and return to a query table
Set oQt = ActiveSheet.QueryTables.Add(Connection:=sConn, Destination:=Range("B1"), Sql:=sSql)
oQt.Refresh ' it stops right here when there's no data, otherwise it runs fine...
I would like to be able to trap the fact that there's no data, send the user a msg, and exit the sub.