multiple recordsets - error 3704

Timtropolis

Registered User.
Local time
Today, 11:29
Joined
Jun 17, 2004
Messages
84
Greetings all,

Have a unique scenario here.
I am calling a stored procedure in SQL Server 2008 from my Access 2010 database. (see my code below).

Code:
Dim objConnection As New ADODB.Connection
    Dim objCom As ADODB.Command
    Dim x, y As Variant
    Dim rst, rst2 As ADODB.Recordset
        
    Set objCom = New ADODB.Command
    
    objConnection.Provider = "sqloledb"
    provStr = "Data Source=Server01;" & "Initial Catalog=xxxx;
        User Id=xxxx;Password=xxxx;"
    objConnection.Open provStr
    
    x = 38600 'for testing purposes
    
    With objCom
        .ActiveConnection = objConnection
        .CommandText = "pr_GetOrder (" & x & ")"
        .CommandType = adCmdStoredProc
        Set rst = .Execute
    End With

    [COLOR="Red"]rst.MoveFirst [/COLOR]<-- Run-time error '3704':
Operation is not allowed when the object is closed.

The stored proc returns two completely different recordsets. When I try
to reference the recordset I get the 3704 error.

My question: Is there any way Access can reference the recordsets created by the SQL Server proc? I've tried using indexing when declaring the recordsets as well as the .NextRecordSet method to no avail.

Any help would be most welcome.
TIA,
Tim
 
Last edited:
In your code:
Code:
Dim objConnection As New ADODB.Connection
    Dim objCom As ADODB.Command
    Dim x, y As Variant                         'Both variant. 
    Dim rst, rst2 As ADODB.Recordset  ' rst = variant, rst2 = ADODB.Recordset
use the following instead:
Code:
Dim objConnection As New ADODB.Connection
    Dim objCom As ADODB.Command
    Dim lngX as Long                   'lngX=long. Y not used. Don't use variant (slow)
    Dim rst as ADODB.recordset, rst2 As ADODB.Recordset  ' both = ADODB.Recordset
The rest of your code:
Code:
    Set objCom = New ADODB.Command
    
    objConnection.Provider = "sqloledb"
    provStr = "Data Source=Server01;" & "Initial Catalog=xxxx;
        User Id=xxxx;Password=xxxx;"
    objConnection.Open provStr
    
    lngX = 38600 'for testing purposes
    
    With objCom
        .ActiveConnection = objConnection
        .CommandText = "pr_GetOrder (" & cstr(lngX) & ")"
        .CommandType = adCmdStoredProc
        Set rst = .Execute
    End With

    If not rst.EOF then
        rst.MoveFirst
    end if


HTH:D
 
Thx Guus, but that didn't resolve the problem.

Anyone else?
 

Users who are viewing this thread

Back
Top Bottom