What is Subscript out of range in MSACCESS?

  • Thread starter George Nicholson
  • Start date
G

George Nicholson

Collections and Arrays use subscripts to designate the position of the
value/object within the Collection/Array.
You will get a "subscript out of range" error if you try to reference a
position that doesn't exist. For example:

For i = 0 to 100
Debug.Print CurrentDb.Tabledefs(i).Name
Next i

The above loop would print the first 101 tables names from the current
database (counting starts at zero). However, if you only have 20 tables in
the database, you would get a "subscript out of range" error once i becomes
19. One way to avoid this without hard-coding values would be to use this
instead:
For i = 0 to CurrentDB.TableDefs.Count -1

If looping through an array, you would use something like:
For i = Lbound(arr) to Ubound(arr).

Not sure how you could get that error in a query unless you are using a
custom function.


HTH,
 
M

Marshall Barton

Jnag wrote:


A short explanation of your problem does more for getting a
useful answer than posting nothing.

The error message in your subject means that you used an
array index that is outside the bounds specified in the
array's declaration.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top