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
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,
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
instead:19. One way to avoid this without hard-coding values would be to use this
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,