Article ID: 182290
Article Last Modified on 3/14/2005
CREATE PROCEDURE Multi_Results AS SELECT * FROM Authors SELECT * FROM Stores SELECT * FROM Sales GONOTE: You need to acquire and install the Microsoft Data Access Components (MDAC) 2.x stack for the sample in this article. Please refer to the article listed in the REFERENCES section for more information on MDAC 2.x.
Private Sub Command1_Click()
Dim Conn1 As ADODB.Connection
Set Conn1 = New ADODB.Connection
Dim Cmd1 As ADODB.Command
Set Cmd1 = New ADODB.Command
Dim Rs1 As ADODB.Recordset
Dim RSField As ADODB.Field
Dim ColCnt, Cnt1, i As Long
Debug.Print "----Starting-----"
'Create all the objects required by this application.
'
'The connection string will have to be modified to reflect your data
'source name (DSN).
Conn1.Open "MyDSN", "sa", ""
Conn1.DefaultDatabase = "pubs"
Conn1.CursorLocation = adUseServer
'Conn1.CursorLocation = adUseClient 'This will give error 3251 -
'"The operation requested by the application
'is not supported by the provider" when calling
'the NextRecordset method.
'Actually, the above is not true for ADO 2.1 sp2,
'and possibly other versions as well. This will
'have to be changed to say
'"Older versions of the OLE DB Provider for
'ODBC Drivers will give error 3251."
Cmd1.ActiveConnection = Conn1
Cmd1.CommandType = adCmdStoredProc
Cmd1.CommandText = "Multi_Results"
'Opens a Forward-Only, Read-Only Recordset cursor.
Set Rs1 = Cmd1.Execute
'Continue looping while there are recordsets to process.
Do Until Rs1 Is Nothing
ColCnt = Rs1.Fields.Count
Debug.Print "The Recordset State is " & Rs1.State
Debug.Print "The Column Count is: " & ColCnt
Do While Not Rs1.EOF 'Cycle through the Recordset.
Debug.Print "Next Record:"
Cnt1 = 0
'Cycle through the Field collection.
For Each RSField In Rs1.Fields
Debug.Print " " & RSField.Name & " = " & Rs1(Cnt1)
Cnt1 = Cnt1 + 1
If Cnt1 = ColCnt Then
Exit For
End If
Next RSField
Rs1.MoveNext
Loop
'Put a breakpoint here to see the last results in the Debug
' window.
Set Rs1 = Rs1.NextRecordset
If Not Rs1 Is Nothing Then
Debug.Print
Debug.Print "***** NEXT RECORDSET *****"
Else
Debug.Print
Debug.Print "***** THE END *****"
End If
Loop
Unload Me 'Quit the application.
End Sub
Keywords: kbhowto kbstoredproc kbdatabase KB182290