1

I need to create an array in excel vba from an access table field. The table has 4 fields, but what I need is to create an array that contains only data from field 2. I did the connection to access, then I use this code to fill the array:

Array1 = Array(Rs.Fields(1).Value)

But Array1 only loads 1 item from field 2 and I don't know how can I make the loop to load all the data.

1 Answer 1

1

We need to use dynamic arrays, and move the recordset in a loop.

Dim array1() As Variant
Do Until Rs.EOF
    n = n + 1
    ReDim Preserve array1(1 To n)
    array1(n) = Rs.Fields(1).Value
    Rs.MoveNext
Loop

The method of getting the entire recordset as an array is as follows, but the rows and columns are transposed.

array1 = Rs.GetRows
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.