How to execute special SQL Server stored procedure through Excel VBA? Special because it does not return rows like this procedure:
select * from tab1
How to execute the procedure which let's say prepares reports, like this one:
select *
into tab2
from tab1
which does not return any rows.
I am using this VBA code:
Dim cnn As Object
Set cnn = CreateObject("ADODB.Connection")
Dim cmd As Object
Set cmd = CreateObject("ADODB.Command")
Dim rs As Object
Set rs = CreateObject("ADODB.Recordset")
Dim ConnectionString As String
cnn.ConnectionString = "driver={SQL Server};server=MYSERVERNAME;Database=MYDATABASE;Trusted_Connection=yes;"
cnn.Open
Sql = "EXEC [dbo].[Procedure_make_report] 'param1'"
Set rs = cnn.Execute(Sql)
I get the error:
Runtime error 2147217900
I found a clue here: http://www.vbforums.com/showthread.php?541498-RESOLVED-runtime-error-2147217900-(80040e14)-incorrect-syntax-error
but I do not know what action query is.
cnn.Executeto run a SQL command or a stored procedure. It's not really clear where your error happens currently.Set rs = cnn.Execute(Sql)Can you write full line of VBA code please.cnn.Execute SqlSET NOCOUNT ONat the top of your stored procedure. Excel can often throw an error if this is not included.