I am trying to place all of the records in a record set into an array so that I can use the values without having to keep the recordset. There are 6 records in the recordset. The value of the record count changes as I step through the code. At the beginning of the code, the recordcount has a value of 1, so strFilterOptions is dimensioned from 1 to 3. But as the code progresses, the recordcount value suddenly changes to 6, the correct amount. Since the array is dimensioned to 3, the Do While loop results in a subscript out of range error for the array.
Can someone tell my why this is happening?
-Joshua
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
Code:
strSQL = "SELECT [Reason] FROM tblOutOfTownReasons"
Set rstRecords = dbDataBase.OpenRecordset(strSQL)
Debug.Print rstRecords.RecordCount [COLOR=red] (Here the recordcount is 1) [/color]
ReDim strFilterOptions(1 To rstRecords.RecordCount + 2)
strFilterOptions(1) = "All Contacts"
strFilterOptions(2) = "In Town"
J = 2
rstRecords.MoveFirst
Do While Not rstRecords.EOF [COLOR=red] (Here the recordcount value suddenly changes to the correct amount) [/color]
J = J + 1
strFilterOptions(J) = rstRecords![Reason]
rstRecords.MoveNext
Loop
Can someone tell my why this is happening?
-Joshua
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]