Search code examples
vbarecordset

Using GetRows on Recordset object returns no rows


I am trying to load a recordset into an array. I am using the following code:

Set rst = CurrentDb.OpenRecordset("SELECT id FROM TABLE1")  
bankacid = rst.GetRows()  
rst.Close  
i = UBound(bankacid, 2)   
MsgBox i + 1

This returns no rows. If I use "bankacid = rst.getrows(5)" it works.

I am very new to VBA and would very much appreciate someone pointing out what I am missing.


Solution

  • It would be best to take a step back and say why you want an array, after all, a DAO recorset is much more functional than an array. If an array is really necessary, use ADODB. If you just want to refer to fields and rows, use Move, MoveFirst, MoveLast, MoveNext, MovePrevious and either the name of the field (column) or the ordinal position (.Field(3).