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!

I have declared an array called Not

Status
Not open for further replies.

ejmiller2

Programmer
Jun 3, 2003
38
US
I have declared an array called NotEmailed()

I redim it later in the code as showen....it resizes this fine the FIRST time....any other time it comes across this code it says subscript out of rang....why will it work the first time but not the second...ive checked the numbers the second time around and NumberNotEmailed = 1. The first time NumberNotEmailed = 0. Any ideas?..

ReDim Preserve NotEmailed(0 To (NumberNotEmailed1 + 1), 0 To 1) As String

NotEmailed(0, 0) = rsPayroll!Name
NumberNotEmailed2 = 0

NotEmailed(NumberNotEmailed1, NumberNotEmailed2) = rsPayroll!Name
NumberNotEmailed2 = 1

NotEmailed(NumberNotEmailed1, NumberNotEmailed2) = rsPayroll!SSN
MsgBox "Hello"

NumberNotEmailed1 = NumberNotEmailed1 + 1
 
From Access 2000 Visual Basic Help, ReDim topic (within Statements section in the Contents):

Similarly, when you use Preserve, you can change the size of the array only by changing the upper bound; changing the lower bound causes an error.

Get rid of the "0 To " in both your dimensions and give it another try. it may be getting confused as it does not expect the "To" keyword even though you are not changing the lower bounds.

 
Check out the 'ReDim Statement' in the help file.
If you use the Preserve keyword, you can resize only the last array dimension.

 
Just noticed on the same help page, you can't use "As String" with ReDim either.
 
thanks!...ive gotten further...this is what i have


ReDim Preserve NotEmailed(1, NotEmailed2 + 1)

NumberNotEmailed1 = 0

NotEmailed(NumberNotEmailed1, NumberNotEmailed2) = rsPayroll!Name

NumberNotEmailed1 = 1

NotEmailed(NumberNotEmailed1, NumberNotEmailed2) = rsPayroll!SSN


NumberNotEmailed2 = NumberNotEmailed2 + 1

yet another weird thing. once it run through two times...i get the subscript out of range again. The NotEmailed2 is 2 so it gets past redim then when it runs NotEmailed(NumberNotEmailed1, NumberNotEmailed2) = rsPayroll!Name
it gives the error...im confused

eric
 
hmm...yea sorry guys... ReDim Preserve NotEmailed(1, NotEmailed2 + 1) was suppose to be

ReDim Preserve NotEmailed(1, NumberNotEmailed2 + 1)

thanks for all the help

eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top