Using Arrays

  • Thread starter Thread starter Rich Waag
  • Start date Start date
R

Rich Waag

Access 2000

I need to create & populate an array with the values in a specific field of
a table containing multiple records.

Having trouble first declaring the array with a variable representing the
number of records in a working table.

Once declared, there must be an easy way to populate this array in a loop,
but i'm stuck.

Any ideas would be mucho helpful.

Thanks, Rich
 
Dim vEmail() As Variant

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("test1")
rst.MoveLast
rst.MoveFirst

vEmail = rst.GetRows(rst.RecordCount)
Dim i As Integer

For i = 0 To UBound(vEmail, 1)
Debug.Print vEmail(0, i)
Next i


note that the array is multi-dimension., and will be dimension based on the
record set.

Of course..with the recordset object...it is rather rare these days that I
need to populate an array. The problem with a array is that you can not
manage the updates back to the database. In most cases...you are better off
to use a reocrdset..and not bother with the array...

Also note:

Set rst = CurrentDb.OpenRecordset("test1")

You can use a table name, query name, or just the raw sql like:

Set rst = CurrentDb.OpenRecordset("select Username, EmailAddress from
tblCustomer where city = 'Edmonton'")
 
Back
Top