adodb recordsets and command text

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
I'm very familiar with fetching a query based record set, via Excel VBA adodb connection to an access or SQL table.
Recently, I discovered a whole other level of SQL syntax, allowing one to declare variables and do interesting things.
I wanted to know how I can execute statements that include SQL declares into my record set and can't seem to figure it out. My statements definitely work, since I tehy execute flawlessly in my SQL Visual studio debugger;
The vba screenshot, works if I do a simple query like "SELECT * FROM hrdat.dbo.absence" with no issues, so the connection is open and ready; but seems the query needs to be delivered differently possibly when using declare and other sql syntax; any ideas would be appreciated.
sqltest.JPG
 

Attachments

  • sqltest.JPG
    sqltest.JPG
    75.9 KB · Views: 8

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
after looking around, discovered adding SET NOCOUNT ON; at the beginning of my sql statement, somehow solves the problem. Not sure why, but that's the answer I found.
 
Upvote 0
Solution
In the Messages tab in the SQL query editor, you should be seeing the record count returned by the SELECT statement (or affected record count for action queries). It is the first recordset that your query returns. And you make it silent by using the SET NOCOUNT ON statement as you already figured. So, it looks like VBA gets the first recordset result, and halts since it is not what it is expecting as the desired recordset.

Glad to hear you got the answer, and thanks for posting back for future readers.
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,693
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top