G
Guest
Using VBA code, I am having a problem getting data returned from a SQL Server
2000 Stored Procedure into a ADO Recordset. My Stored Procedure has 2 INPUT
Parameters and all it does is return all records from our Customers table
based on the parameters entered. ie: SELECT * FROM tblCustomers WHERE CustID
= @CustID
I keep getting the error "Run-time error 3704: Operation is not allowed when
the object is closed." when the "MsgBox rs.Fields(0)" line of code is
executed.
My VBA Code is below:
Dim con As ADODB.Connection
Set con = New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Dim sDBConnect As String
sDBConnect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=False;Data Source=REPORTING;Initial Catalog=MyTestDB"
con.Open sDBConnect
Set cmd = New ADODB.Command
cmd.ActiveConnection = con
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "usp_MyStoredProc"
cmd.Parameters.Append cmd.CreateParameter("@CustID", adVarChar,
adParamInput, 10, "GHP")
cmd.Parameters.Append cmd.CreateParameter("@ReportType", adVarChar,
adParamInput, 1, "D")
Set rs = cmd.Execute
MsgBox rs.Fields(0)
Set cmd.ActiveConnection = Nothing
2000 Stored Procedure into a ADO Recordset. My Stored Procedure has 2 INPUT
Parameters and all it does is return all records from our Customers table
based on the parameters entered. ie: SELECT * FROM tblCustomers WHERE CustID
= @CustID
I keep getting the error "Run-time error 3704: Operation is not allowed when
the object is closed." when the "MsgBox rs.Fields(0)" line of code is
executed.
My VBA Code is below:
Dim con As ADODB.Connection
Set con = New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Dim sDBConnect As String
sDBConnect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=False;Data Source=REPORTING;Initial Catalog=MyTestDB"
con.Open sDBConnect
Set cmd = New ADODB.Command
cmd.ActiveConnection = con
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "usp_MyStoredProc"
cmd.Parameters.Append cmd.CreateParameter("@CustID", adVarChar,
adParamInput, 10, "GHP")
cmd.Parameters.Append cmd.CreateParameter("@ReportType", adVarChar,
adParamInput, 1, "D")
Set rs = cmd.Execute
MsgBox rs.Fields(0)
Set cmd.ActiveConnection = Nothing