Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subscript Out of Range Error with Array()

Status
Not open for further replies.

jwoods7

Technical User
Feb 19, 2003
36
US
I've searched this forum and found some common difficulties with this error, the problem is most posts are talking about dynamicly created arrays....don't think mine is.

My array is set like this:

Public Const AcctSub = 0

ReDim Trans(0, 8) As String
Dim Counter as long

Counter = 6
Trans(Counter, AcctSub) = 3 <---xxx ERROR ON THIS LINE

The problem is this code is from another company we purchased code from and they charge for tech support. I'm learning vba but not familiar with arrays

Any clue why it works on some records and not others???
 
to be honest not sure why it would work.

the redim statment defines a 1,9 dimension array.

So if counter is ever greater than 0 there will be an error.

Also if AcctSub is ever greater than 9 you will also get an error.
 
In their code, they have a couple counter = counter + 1 lines

I left out certain elements for simplicity, for example counter is either 1 or 0 to begin with depending on the output of an IF..THEN..ELSE statement.
Also, they had
Trans(Counter, AcctSub) = Format$(InvCOGSAcct)

InvCOGSAcct is the default COGS account from the setup table, our case the value is always '3'Not sure what the Format$() is though, searched and found nothing on that.

Does that help clear things up at all?
 
as i said if counter is greater than 0 you will get an error so where you said

&quot;is either 1 or 0 to begin &quot;

could be your problem as if it is 1 the code will fall over.

change the redim to

ReDim Trans(1, 8) As String
 
No, I don't think that's the problem. When I run the code as it is now, the value of counter gets as high as 43 before errors pop up. Don't know what is going on, but the debugger tells me the value on one Invoice that won't work is '43'.

Tried with reDim trans(1,8) as string
Same issue, confusing code!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top