0

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

1 Answer 1

2

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')"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.