Hi there,
I need to fill an array with two field data from a table in access.
This is my code:
I get a subscript out of range error in this line: ReDim Preserve aryTestArray(UBound(aryTestArray) + 1, UBound(aryTestArray) + 1)
Any advice?
Regards.
I need to fill an array with two field data from a table in access.
This is my code:
Code:
Function FillIndefArray()
Dim dbSample As DAO.Database
Dim rstSample As DAO.Recordset
Dim intArrayCount As Integer
Dim intArrayCount2 As Integer
Dim aryTestArray() As Variant
Dim intCounter As Long
Set dbSample = CurrentDb()
Set rstSample = dbSample.OpenRecordset("AllocationViewTmp")
intArrayCount = 0
ReDim Preserve aryTestArray(0, 0)
' Fill the array.
With rstSample
.MoveFirst
Do Until rstSample.EOF
' Fill the array row with the last name.
aryTestArray(intArrayCount, intArrayCount) = ![ItemOption]
aryTestArray(intArrayCount, intArrayCount) = ![PutInQty]
' Increase the number of elements in the array
' by one to accommodate the next record.
ReDim Preserve aryTestArray(UBound(aryTestArray) + 1, UBound(aryTestArray) + 1)
intArrayCount = intArrayCount + 1
.MoveNext
Loop
' Remove the remaining empty array row.
ReDim Preserve aryTestArray(UBound(aryTestArray) - 1, UBound(aryTestArray) - 1)
.Close
End With
dbSample.Close
' View the array contents.
For intCounter = 0 To intArrayCount - 1
Debug.Print aryTestArray(intCounter, intCounter)
Next intCounter
End Function
I get a subscript out of range error in this line: ReDim Preserve aryTestArray(UBound(aryTestArray) + 1, UBound(aryTestArray) + 1)
Any advice?
Regards.