I have some strange behavior with a dynamic array. It seems like VBA denies assigning a value to a variable. Here is the code:
Private Sub Report_Load()
Dim db As Database
Dim reportArray() As Variant
Dim structre As Recordset
Dim columns, rows, i As Integer
'Open recordset
Set db = CurrentDb
Set structure = db.OpenRecordset("SELECT * FROM [tblstructure] ORDER BY [Rank]")
'Change array size dynamically
rows = structure.RecordCount
columns = 4
ReDim reportArray(rows, columns)
'Populate array
i = 0
Do Until structure.EOF
reportArray(i, 0) = structure![Name]
i = i + 1
structure.MoveNext
Loop
End Sub
When I open the report I get an error that subscript is out of range. When I debug my code I can see that value of i in the loop is 2, so my array must be smaller that that. When I hover over rows variable I see that its value is 1. So indeed I'm trying to access something that is out of range. But the strange part is that the value of structure.RecordCount is 23.
A screenshot:

Even if I use the code like this:
ReDim reportArray(structure.RecordCount, columns)
I get an array of size (1, 4). Why isn't VBA assigning value 23 to variable "rows" or why ReDim assigns the right value to second dimension, but not the first?
GetRows()method of the DAO.Recordset.