Excel VBA How to detect that SQL query returned no data?
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.
Never mind. I just added a teeny query to check the SQL database for the account number, and returned a '0' if it was not found. Since the teeny query will ALWAYS return something, I'm able to handle it on the VBA side.
Thanks anyway!
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Thanks anyway!