Here is how you would add a row at a time to the array (I've used the
Employees table in Northwind, so that I could test the result before
posting) ...
Public Sub TestArray1()
Dim varTest()
Dim rst As ADODB.Recordset
Dim lngRows As Long
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT FirstName, LastName FROM Employees"
.Open
Do Until .EOF
ReDim Preserve varTest(1, lngRows + 1)
varTest(0, lngRows) = .Fields("FirstName")
varTest(1, lngRows) = .Fields("LastName")
lngRows = lngRows + 1
.MoveNext
Loop
.Close
End With
For lngRows = 0 To UBound(varTest, 2)
Debug.Print varTest(0, lngRows); " "; varTest(1, lngRows)
Next lngRows
End Sub
However, once you have the recordcount, you can dimension the array once,
and avoid the need to use Preserve, which will be much more efficient ...
Public Sub TestArray2()
Dim varTest()
Dim rst As ADODB.Recordset
Dim lngRows As Long
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseClient
.Source = "SELECT FirstName, LastName FROM Employees"
.Open
ReDim varTest(1, .RecordCount - 1)
Do Until .EOF
varTest(0, lngRows) = .Fields("FirstName")
varTest(1, lngRows) = .Fields("LastName")
lngRows = lngRows + 1
.MoveNext
Loop
.Close
End With
For lngRows = 0 To UBound(varTest, 2)
Debug.Print varTest(0, lngRows); " "; varTest(1, lngRows)
Next lngRows
End Sub

Signature
Brendan Reynolds (MVP)
> I'm attempting to use a dynamic array and I'm having two problems:
>
[quoted text clipped - 44 lines]
> End With
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
MikeC - 14 Feb 2005 21:27 GMT
Excellent code. Thanks Brendan.
I can now see part of the problem I was having. The wording of the online
help ("Declaring Arrays") had lead me to think that the first element in the
below array was the row and the second array element was the column. After
reading your code, I see that I had it backwards!
I also prefer the way you are using the recordset properties. I'll adopt
this method as my new standard.
Thanks again.
> Here is how you would add a row at a time to the array (I've used the
> Employees table in Northwind, so that I could test the result before
[quoted text clipped - 104 lines]
>> End With
>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<