G
Guest
Good evening,
I have the following code to run through records and populate an array.
*****
Dim arrDwgID() As Variant
Dim intCounter As Long
Dim intArrayCounter As Integer
intArrayCounter = 0
ReDim Preserve arrDwgID(0)
Set rst = CurrentDb.OpenRecordset("Drawing History Tbl")
With rst
If .RecordCount > 0 Then
.MoveFirst
Do Until rst.EOF
If rst("Drawing Number") = DwgNum Then
If rst("Drawing Issue") <> DwgIssue Then
arrDwgID(intArrayCounter) = ![Id]
ReDim Preserve arrDwgID(UBound(arrDwgID) + 1)
intArrayCounter = intArrayCounter + 1
End If
End If
.MoveNext
Loop
ReDim Preserve arrDwgID(UBound(arrDwgID) - 1)
End If
.Close
End With
*****
My problem is that I am receiving an error 9 subscript out of range and the
debugger is highlighting the 'ReDim Preserve arrDwgID(UBound(arrDwgID) - 1)'
line.
I believe it to be because of the fact that arrDwgID is empty in this
specific case? What code change do I need to make to be able to manage this
type of exception?
Thank you,
Daniel
I have the following code to run through records and populate an array.
*****
Dim arrDwgID() As Variant
Dim intCounter As Long
Dim intArrayCounter As Integer
intArrayCounter = 0
ReDim Preserve arrDwgID(0)
Set rst = CurrentDb.OpenRecordset("Drawing History Tbl")
With rst
If .RecordCount > 0 Then
.MoveFirst
Do Until rst.EOF
If rst("Drawing Number") = DwgNum Then
If rst("Drawing Issue") <> DwgIssue Then
arrDwgID(intArrayCounter) = ![Id]
ReDim Preserve arrDwgID(UBound(arrDwgID) + 1)
intArrayCounter = intArrayCounter + 1
End If
End If
.MoveNext
Loop
ReDim Preserve arrDwgID(UBound(arrDwgID) - 1)
End If
.Close
End With
*****
My problem is that I am receiving an error 9 subscript out of range and the
debugger is highlighting the 'ReDim Preserve arrDwgID(UBound(arrDwgID) - 1)'
line.
I believe it to be because of the fact that arrDwgID is empty in this
specific case? What code change do I need to make to be able to manage this
type of exception?
Thank you,
Daniel