Reputation: 433
I've been looking at this statement for ages and I'm sure its something minor. However I cannot get it to pull the data through via VBA. Strange thing is it works in SQL as a statement but as soon as I run it through VBA I get a runtime error. I could really do with a second pair of eyes.
stSQL = "EXEC('SELECT T1.Name FROM [dbo].[Tbl1] T1 " & _
"INNER JOIN [dbo].[Tbl2] T2 ON T1.ID = T2.ID " & _
"WHERE T2.NAME = '" & sBizUnit & "' AND Desc = '''' ORDER BY Name')"
sBizUnit is a value from a combobox:
sBizUnit = CB_BizU.Value
Thanks in advance
Upvotes: 0
Views: 363
Reputation: 2403
Does the account you are running your application under have permission to run the EXEC
command?
Another point I've noticed is that you haven't escaped the first set of quotation marks, maybe try:
stSQL = "EXEC('SELECT T1.Name FROM [dbo].[Tbl1] T1 " & _
"INNER JOIN [dbo].[Tbl2] T2 ON T1.ID = T2.ID " & _
"WHERE T2.NAME = ''" & sBizUnit & "'' AND Desc = '''' ORDER BY Name')"
Upvotes: 2