Link to home
Create AccountLog in
Avatar of Eric Harris
Eric Harris

asked on

Run SQL Store Procedure using Excel VBA

Hi there,

I need to run a store procedure or SQL job from within excel.
I have a storeprocedure which dies some extensive data manipulation and creates a summarized table.

I then use this table to run queries with excel. (No problem ith this.

I'd like to be able to run the stored procedure in vbas priot to doing my query refresh.

I've looked on varios discusions in ~EE and have tried a few.

The last one suggested putting my sp in a job and then running the job.

I'm obviously doing something wrong but can someone please help

Here's my vba code to run the SQL job


Dim c As ADODB.Connection
Set c = New ADODB.Connection
'c.Open "Provider=SQLOLEDB.1;User ID=sa;Initial Catalog=EB_Production;Data Source=EBDBSQL\EBSQL;PWD=3ntri3$$"
c.Open "DRIVER=SQL Server;SERVER=EBDBSQL\EBSQL;UID=sa;PWD=3ntri3$$;APP=Microsoft Office 2003;WSID=EBDBSQL;DATABASE=EB_Production"
c.Execute "exec msdb.dbo.sp_start_job @job_name = 'Packing_Invoicing' "
c.Close
Set c = Nothing


also here's an example connection string from one of the queries. Don't know if that's relevant

DRIVER=SQL Server;SERVER=EBDBSQL\EBSQL;UID=sa;APP=Microsoft Office 2003;WSID=EBDBSQL;DATABASE=EB_Production
ASKER CERTIFIED SOLUTION
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Eric Harris
Eric Harris

ASKER

Thanks for that.
I tried it and I'm getting an syntax error on the .parameters line
Whoops...

Change:

'Packing_Invoicing'

To

"Packing_Invoicing"