This method returns data stored in the recordset.
Syntax
array = recordset.GetRows(Rows, Start, Fields)
Parameters
Array
Variant variable that contains returned data.
Rows
Optional. Long expression that indicates the number of records to retrieve. The default value is either adGetRowsRest or –1.
Start
Optional. String or Variant that is the bookmark for the record from which the GetRows operation should begin.
Fields
Optional. Variant that represents a single field name or ordinal position or an array of field names or ordinal position numbers. ADOCE returns only the data in these fields.
Remarks
Use the GetRows method to copy records from a Recordset into a two-dimensional array. The first subscript identifies the field and the second identifies the record number. The array variable is automatically set to the correct size when the GetRows method returns the data.
If you do not specify a value for the Rows parameter, the GetRows method automatically retrieves all the records in the Recordset object. If you request more records than are available, GetRows returns only the number of available records.
If the Recordset object supports bookmarks, you can specify at which record the GetRows method should begin retrieving data by passing the value of the Bookmark for that record property.
If you want to restrict the fields the GetRows call returns, you can pass a single field name or number, or an array of field names or numbers in the Fields parameter.
After you call GetRows, the next unread record becomes the current record. If there are no more records, ADOCE sets the EOF property to True.
Example
The following code example shows how to use the GetRows method to retrieve and display data in a requested number of rows.
Dim rstEmployees, strMessage
Dim intRows, avarRecords
Dim intRecord, intField
Dim intRecCount, intFieldCount
Set rstEmployees = CreateObject("adoce.recordset")
rstEmployees.Open "myTable"
strMessage = "Enter number of rows to retrieve."
intRows = CInt(InputBox(strMessage))
If intRows <= 0 Then intRows = 1
' If GetRowsOK is successful, print the results,
' noting if the end of the file was reached.
If GetRowsOK(rstEmployees, intRows, avarRecords) Then
If intRows > UBound(avarRecords, 2) + 1 Then
MsgBox "Less than " & intRows & " rows in recordset."
End If
intRecCount = UBound(avarRecords, 2) + 1
intFieldCount = UBound(avarRecords, 1) + 1
MsgBox intRecCount & " records found."
MsgBox intFieldCount & " fields found."
For intRecord = 0 To intRecCount - 1
strMessage = ""
For intField = 0 To intFieldCount - 1
strMessage = strMessage & _
avarRecords(intField, intRecord) & vbCrLf
Next
MsgBox strMessage
Next
Else
MsgBox "GetRows failed!"
End If
rstEmployees.Close
Set rstEmployees = Nothing
Public Function GetRowsOK(rstTemp, intNumber, avarData)
' Store results of GetRows method in array.
avarData = rstTemp.GetRows(intNumber)
' Return False only if fewer than the desired
' number of rows were returned, but not because the
' end of the Recordset was reached.
If intNumber > UBound(avarData, 2) + 1 And Not rstTemp.EOF Then
GetRowsOK = False
Else
GetRowsOK = True
End If
End Function