|
-
May 25th, 2000, 03:45 AM
#1
Thread Starter
Addicted Member
Anyone know the code to run a stored procedure in VBA or VB and populate Excel with the results -- I would take VB as well, but prefer VBA
-
May 25th, 2000, 04:43 AM
#2
Hyperactive Member
I know VBA. I don't understand what you are trying to do. What do you mean by a stored procedure?
-
May 25th, 2000, 05:34 AM
#3
Thread Starter
Addicted Member
How could I run a query or stored procedure from SQL in Excel. A stored procedure sits on the table in SQL ( a group of queries, essentially) and can be scheduled to execute manually or automatically.
-
May 29th, 2000, 09:58 PM
#4
Hyperactive Member
That I don't know. Any ideas, Yonatan?
-
May 30th, 2000, 12:04 AM
#5
Fanatic Member
I have to go to a meeting right now, but when I come back I will search for the codes.
Off hand you have to use the command Execute with Parameters.
Chemically Formulated As:
Dr. Nitro
-
May 30th, 2000, 04:52 AM
#6
Fanatic Member
Hello Bebe!
Try this and give me an update!
Code:
Private conn As Connection
Private cmd As Command
Sub p_Stored_Procedure()
'PURPOSE: Open the Connection
Set conn = CreateObject("ADODB.Connection")
conn.open "dsn=dsn;uid=username;pwd=password"
'PURPOSE: Call Stored Procedure
Set cmd = CreateObject("ADODB.Command")
Set cmd.activeconnection = conn
cmd.commandtext = "Procedure_name"
cmd.commandtype = adcmdStoredProc
cmd.Parameters.Refresh
cmd.Parameters(1).Value = "Value1"
cmd.Parameters(2).Value = "Value2"
cmd.Parameters(n).Value = "Valuen"
'PURPOSE: Get the results from the Stored Procedure
Dim varReturn As Variant
cmd.Execute
varReturn = cmd.Parameters(0).Value
'PURPOSE: Get the results set from Stored Procedure
Dim rs As Recordset
Set rs = cmd.Execute
conn.Close
End Sub
Chemically Formulated As:
Dr. Nitro
-
May 30th, 2000, 04:57 AM
#7
Fanatic Member
After you get the above code to work. I will be happy to help you populate the Result Sets into Excel. One thing at a time, otherwise you might get confuse.
Chemically Formulated As:
Dr. Nitro
-
May 30th, 2000, 09:17 AM
#8
Thread Starter
Addicted Member
Wow, thank you this is a great start. I need to get the stored procedures done and I will take you up on your offer. What I have is a formatted type report in Excel -- with colors and stuff. Does than make it any more difficult. No, charts though!!!
Thanks again!!!
-
May 30th, 2000, 11:12 AM
#9
Fanatic Member
Hello Bebe,
I recommend you do a small test stored procedure
first. The more complicated the stored procedure, the
more difficult to understand where the problem.
Once your stored procedure runs fine, then test the
vb code against the stored procedure.
I have been doing Excel VBA for a while so that should
be the easy part.
Good Luck!
To populate the spreadsheet, do either a CreateObject
or GetObject against Excel.
Chemically Formulated As:
Dr. Nitro
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|