J
JamesM
I have SQL Server 2005 as my database and Microsoft Access 2002. I'm trying
to open a recordset from a lengthy stored procedure in VBA. I have no
trouble returning data from simple SQL queries, but I keep getting an error
that the recordset is not open when attempting to get a recordset from a
particular stored procedure. The stored procedure executes and returns a
recordset in a Query window in SSMS.
I've been working on this off and on for a week. I would truly appreciate
any hints on where to look for the source of the problem. I have tried
several methods of calling the stored procedure. Every one returns the same
error. Here is the code I am currently using:
Dim oRsSales As ADODB.Recordset
Dim cmdSQL As New ADODB.Command
Dim cmdConn As New ADODB.Connection
Set cmdConn = New ADODB.Connection
cmdConn.ConnectionString = CurrentProject.Connection
cmdConn.Open
Set oRsSales = New ADODB.Recordset
With cmdSQL
.ActiveConnection = CurrentProject.Connection
.CommandType = adCmdStoredProc
.CommandText = "sp_SalesByRep"
.Parameters.Append .CreateParameter("@year1", adInteger, adParamInput, 1,
6)
.Parameters.Append .CreateParameter("@year3", adInteger, adParamInput, 1,
8)
End With
Set oRsSales = cmdSQL.Execute()
If Not (oRsSales.BOF = True And oRsSales.EOF = True) Then
On this last line I get the following error:
Operation is not allowed when the object is closed.
to open a recordset from a lengthy stored procedure in VBA. I have no
trouble returning data from simple SQL queries, but I keep getting an error
that the recordset is not open when attempting to get a recordset from a
particular stored procedure. The stored procedure executes and returns a
recordset in a Query window in SSMS.
I've been working on this off and on for a week. I would truly appreciate
any hints on where to look for the source of the problem. I have tried
several methods of calling the stored procedure. Every one returns the same
error. Here is the code I am currently using:
Dim oRsSales As ADODB.Recordset
Dim cmdSQL As New ADODB.Command
Dim cmdConn As New ADODB.Connection
Set cmdConn = New ADODB.Connection
cmdConn.ConnectionString = CurrentProject.Connection
cmdConn.Open
Set oRsSales = New ADODB.Recordset
With cmdSQL
.ActiveConnection = CurrentProject.Connection
.CommandType = adCmdStoredProc
.CommandText = "sp_SalesByRep"
.Parameters.Append .CreateParameter("@year1", adInteger, adParamInput, 1,
6)
.Parameters.Append .CreateParameter("@year3", adInteger, adParamInput, 1,
8)
End With
Set oRsSales = cmdSQL.Execute()
If Not (oRsSales.BOF = True And oRsSales.EOF = True) Then
On this last line I get the following error:
Operation is not allowed when the object is closed.