Subscript out of range error

  • Thread starter Thread starter MDW
  • Start date Start date
M

MDW

I've got a database in Access 97 that records the items
shipped and received for a warehouse. Because of the
nature of the operation, I can't know any advance how many
items will be included on a shipment - it could be 1, it
could be 50. (I think it's a reasonable thing to assume
that we'll never break 100 items per shipment.)

To accomidate, I've got a dynamic string array that stores
the values in VB. I've got 5 unbound text boxes, and my
form reads their values, increases the size of the array,
and adds the value the newly created slot. On my system
(the development PC), it works like a charm. I could add
15 or 20 things, and the items are added OK.

However, on the PCs down in the warehouse, they tell me
they will often get "Subscript out of range" errors -
sometimes two or three times in a row. The actual line
that throws the error is this one:

ReDim Preserve myArr(UBound(myArr) + 1)

The only difference I can think of is that on their
system, there could be a 15 or 20 minute wait period
between the times that they add items. Whereas when I test
it, I add all the items at once and process the thing.

Is there some kind of "time out" or something where VBA
will "forget" what was in the array? Or does anyone else
have a suggestion for another method by which I can
dynmically save multiple items in VBA?
 
#1. I don't know how a Redim statement throws "Subscript
out of range" error. (But, I've been wrong before!)

I would strongly encourage a revisit to find the line that
actually raises the error. I would bet you'd find it was
a line that referenced the array (and the element would be
out of bounds).

Therefore, I believe your problem is exactly as the error
states: somewhere in your code you're reference an array
element higher than the maximum bound or lower than the
minimum bound.

#2: More of a pet peeve than anything else, but I'd
recommend that you don't Redim Preserve arrays in
increments of 1. If you need to redim, redim in larger
blocks.

The idea of the operating system allocating a new memory
location, copying data from location old to location new,
then deallocating location old for ONE more element gives
me the heebies. Bah, it's a peeve what can I say.

Grey
 
Back
Top