Forum Discussion
dynamictiger
Jan 10, 2020Copper Contributor
Why Cant I Populate an Array from ADO.Recordset?
Perhaps this is obvious, however I seldom use arrays. In fact I am struggling to recall last time I used this as my code usually doesn't need it. However in this instance I think it is the best cho...
MapperZapper
Jan 14, 2020Copper Contributor
In your case as been posted you are looping through the entire recordset so you can assign one value a time to the array. Then you should use an array index:
Dim i as integer
...
Do while not rst.eof
i = i + 1
mlngJob[i] = .fields("job")
rst.MoveNext
Loop
Another solution - and I assume this is the solution you are looking for - is assigning the recordset rows directly to an array
...
Dim rst As Recordset
Dim mstrArray As Variant
Set rst = CurrentDb.OpenRecordset("yourSQLstatement")
mstrArray = rst.GetRows()
Set rst = Nothing
...