Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating an array with a recordset 1

Status
Not open for further replies.

Gavuk

Programmer
Apr 16, 2003
32
GB
Hiya all,

Can anyone tell me how i can populate an array (and set one up) to store values from a record set?

Cheers
 
Dim i As Integer
Dim j As Long
rst.Open "Select WhateverFields from WhateverTable;", CurrentProject.Connection, adOpenForwardOnly
ReDim ArrayName(rst.Fields.Count - 1, 0)
While Not rst.Eof
For i = 0 To rst.Fields.Count - 1)
ArrayName(i, j) = rst.Fields(i)
Next i
j = j + 1
Redim Preserve ArrayName(UBound(ArrayName,1), j)
rst.MoveNext
Wend

That's all...

Good luck



[pipe]
Daniel Vlas
Systems Consultant

 
or you could try GetRows.

dim rs as DAO.Recordset
dim vArray as variant

'set your recordset....


vArray=rs.getrows(1000)

will put 1000 rows into the array. If you want all the rows, then either put a number bigger than all the rows in or use vArray=rs.getrows(rs.recordcount)

hth

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
I believe you Dan!
Don't you just hate it when you miss something simple!!

Cheers mate

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top