Re: RecordSet.Close Throwing Errors



I call a stored procedure that returns either 1, 2 or 3 recordsets.

You did do

Dim rs as ADODB.Recordset
Set rs = New ADODB.Recordset
and not
Dim rs as New Recordset

I loop through the recordsets using
Do Until rs Is Nothing

Looping through what?
I assume you mean

rs.= rs.NextRecordSet

when you have finished with the current recordset.

As I don't know how to determine how many recordsets there are. Is there a
method for doing this?

I don't think there is (but if there was, it would be a dynamic property)

Lastly after I'm done I call rs.close
However if I've ran out of recordsets in the above loop this throws an
error
also.
Is it sufficient to just set rs = nothing instead of rs.close?

No.
I am not at work right now, so I can't consult resources. This is being
recalled from memory (so it may be wrong in places, mostly pseudocode)
But I think you should have something like

'populate rs

Do Until rs Is Nothing
Do
' Loop over Recordset using MoveNext(), whatever
Loop
If (rs.state AND ADOOpenConstant) <> 0 THEN
rs.Close
END IF
rs = rs.NextRecordSet
Loop

Stephen Howe







.



Relevant Pages

  • Re: AutoTextList? UserForm? Macros? Not sure which way to go...
    ... Dim rs As DAO.Recordset ... ' Set the number of Columns = number of Fields in recordset ... the list of named ranges that exist in the Excel spreadsheet. ... The next change is to insert a For...Next loop around the code that reads ...
    (microsoft.public.word.vba.general)
  • Re: access 2003
    ... Dim ctl As Control ... Dim rs As Recordset ... This sets the query definitions for choosing data to create an invoice using ... Event on combo box: Private Sub ChooseCust_AfterUpdate ...
    (microsoft.public.access.conversion)
  • Re: Befüllen aus RS klappt nicht
    ... Loop ... Dim rs1 As Recordset ... Wenn ich nun auch rs1.MoveNext aktiviere UND Next i belasse, ...
    (microsoft.public.de.access)
  • RE: Need help with an If then statement before a loop
    ... use it as a recordset then cycle throught that recordset checking the table ... That would be the outer loop. ... Dim db As Database ...
    (microsoft.public.access.modulesdaovba)
  • Re: Keep getting an Subscript Out of Range....
    ... sLabel As String ... Dim CircPts() As POINTAPI ... The recordset has a RecordCount property that is known ... before entering the loop. ...
    (microsoft.public.vb.general.discussion)