bluecjh
Programmer
- Mar 12, 2003
- 385
I have a fairly complex union query stored in access (INSERT INTO table etc...)
This query runs fine inside Access inserting plenty of rows into my table. However, I want to be able to run the stored query from Excel. Using ADODB and a command object and after much trial and error the code runs :
Sub CommandAndExec()
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set conn = New ADODB.Connection
With conn
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\Users\bluecjh\documents\AccessTest.accdb"
.Open
End With
Set cmd = New ADODB.Command
With cmd
Set .ActiveConnection = conn
.CommandText = "qrySkillReport"
.CommandType = adCmdStoredProc
.Execute
End With
conn.Close
Set conn = Nothing
End Sub
But generates no rows in my table. Is there a command parameter that needs to be set, or is it in the connection. Thanks for any help.
BlueCJH
This query runs fine inside Access inserting plenty of rows into my table. However, I want to be able to run the stored query from Excel. Using ADODB and a command object and after much trial and error the code runs :
Sub CommandAndExec()
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Set conn = New ADODB.Connection
With conn
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\Users\bluecjh\documents\AccessTest.accdb"
.Open
End With
Set cmd = New ADODB.Command
With cmd
Set .ActiveConnection = conn
.CommandText = "qrySkillReport"
.CommandType = adCmdStoredProc
.Execute
End With
conn.Close
Set conn = Nothing
End Sub
But generates no rows in my table. Is there a command parameter that needs to be set, or is it in the connection. Thanks for any help.
BlueCJH