Secondary Array is out of range (1 Viewer)

AccessIsEggs

New member
Local time
Today, 07:22
Joined
Jul 24, 2019
Messages
9
Hi all,

I was curious if someone could tell me why my arr2 is out of range, I can't seem to figure out what is going on with it.

Dim arr2() As String
ReDim arr2(0)

Dim j As Integer

For i = LBound(arr) To UBound(arr)
If arr(i) = arr(i + j) Then
For j = 0 To 200

k = (i + j)

If arr(i) = arr(k) Then
arr2(z) = Worksheets("BOM ").Cells(k, 2).Value
ReDim Preserve arr2(z)
z = z + 1
Else
Exit For
End If

Next
Else
'code will be here
End If
Next

I've checked to see if it was the
worksheets("BOM ").cells(k, 2).value
that was causing my error, and it is not.
arr2(z) goes to <subscript out of range>

Thank you very much for any input.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:22
Joined
Oct 29, 2018
Messages
21,358
Hi. First you declared arr2() as:
Code:
Dim arr2() As String
Then, you gave it a size with:
Code:
ReDim arr2(0)
So, I could be wrong but doesn't that makes your arr2() array only have room for one value?
 

Micron

AWF VIP
Local time
Today, 10:22
Joined
Oct 20, 2018
Messages
3,476
Surely you do not have Option Explicit at the top of this and every module? Not only are you using variables that your code doesn't declare, you're using them before setting values (such as j). Does this code compile?

Do us a favour if you will - post code withing code tags and copy & paste in between them. In this case, I suspect things are missing, as I can't see how you can have such a worksheet reference like that from within Access code.
 

Users who are viewing this thread

Top Bottom