Put Values form the Table into an array

G

Guest

ok, i have a table which only has one field and i need to put all of those
records into one dimentional array so i can use them in the code down the
line.

Any help is apreciated
 
N

Nikos Yannacopoulos

Try this:

Dim strTable As String
Dim MyArray() As String
Dim iRecCount As Long
Dim db As DAO.Database
Dim rst As DAO.Recordset
strTable = "MyTable"
Set db = CurrentDb
Set rst = db.OpenRecordset(strTable)
rst.MoveLast
ReDim MyArray(rst.RecordCount)
rst.MoveFirst
For i = 1 To rst.RecordCount
MyArray(i) = rst.Fields(0)
rst.MoveNext
Next
rst.Close
Set rst = Nothing
Set db = Nothing

Note: requires an appropriate DAO refrence.

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top