You are currently offline, waiting for your internet to reconnect

Use DAO GetRows Method to Fill Variant Arrays

This article was previously published under Q129856
This article summarizes how to use the GetRows method in Visual Basicversion 4.0.

The GetRows method was added to the RecordSet object to facilitate testingfrom Visual Basic of a lower-level C/C++ GetRows method that will be usedby Visual C++ developers. It was later found to be generally useful in manyplaces. This function is not documented in the Visual Basic Help file orthe manuals, but can be found by using the Object Browser under theRecordSet object. It is described in the ReadMe file included with VisualBasic version 4.0.
The GetRows method retrieves multiple rows of a recordset into an array.Here is the syntax:
   variant = recordset.GetRows (numrows)				
  • variant is the name of a variant to hold the returned data.
  • numrows is the number of rows to retrieve.
GetRows returns the specified number of rows and all the fields (columns)into a variant containing an array. Subsequent rows contain the data.

After a call to GetRows, the current record is positioned at the nextunread row. In other words, GetRows has the same positioning effect as Movenumrows.

If more rows are requested than are available, only the number availableare returned. Use Ubound to determine how many rows were actually fetched.The array is sized to fit the number of rows returned.

For example, if you returned the results into a variant called a, you coulduse the following code to determine how many rows were actually returned:
   numreturned = Ubound(a,2) + 1				
The "+ 1" is used because the first data returned is in the zero (0)element of the array.

The number of rows that can be fetched is constrained by available memoryand should be chosen to suit your application. Don't expect to use GetRowsto bring your whole table into an array.

Because all fields of the recordset are returned in the array, includinglong memo and binary fields, you may want to use a query that restricts thecolumns returned.

Code Sample

' This example uses the GetRows method to bring two fields' from the Orders table into memory.Dim db as DatabaseDim rs as RecordsetDim data as VariantSet db = OpenDatabase("sales.mdb")Set rs = db.OpenRecordset("Select OrderId, CustId from Orders")While Not rs.eof   data = rs.GetRows(10)   ' .... do something with the dataWendrs.Closedb.Close				
4.00 Excel vb4win vb4all

Article ID: 129856 - Last Review: 12/09/2003 15:27:00 - Revision: 2.0

  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 16-bit Enterprise Edition
  • Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
  • kbdatabase kbcode KB129856