Run a SQL Stored Procedure from VBA

M

Madiya

I want to run a sql stored procedure from VBA but getting error.
Error is run-time error '-2147467259 (80004005)' and 2nd line 2013-06-20.
I have tried all variations found on google but getting same error.
Here is my code.
===============
Sub Run_SP()
Dim cmd As ADODB.Command
Set con = New ADODB.Connection
con.Open "Provider=SQLOLEDB;Password=anish;User ID=anish;Initial Catalog=cpcom;Data Source=bhw1;Extended Properties=Trusted_Connection=no;"
Set cmd = New ADODB.Command
With cmd
..ActiveConnection = con
..CommandText = "exec cpsrmail"
..CommandType = adCmdText
..Execute
End With
con.Close
Set cmd = Nothing
Set con = Nothing
End Sub
================
Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top