Hello all,
I'm working on a project in VB6, but the code that I have issue with is basically the type of thing that I have recycled from old VBA projects, so I've posted it in this category. I'm populating a multi-dimensional array from a recordset, and it works absolutely fine with my test data. I have several different recordsets which contain various numbers of records, some over a hundred, some with none at all. Every recordset which contains none or more than one works absolutely fine, it's just the scenario where there is just one record.
In this scenario, the second column cannot be populated for some reason, and I am given a subscript out of range error message. Here is my code:
At first I suspected it was the code that moved to the next record, as if there was only one record and before it got to the loop until EOF it was told to move to next, it would generate an error, but after testing I've found that this isn't the error. I have tried removing the line that populates the array position 1,2 and then my record is entered into the array successfully. But it's strange because I have a recordset which contains four records, and both columns are populated for each of the four records, the second column never causes a problem, except for my two recordsets which only have one record each.
Thanks for any help you can offer,
Matthew
I'm working on a project in VB6, but the code that I have issue with is basically the type of thing that I have recycled from old VBA projects, so I've posted it in this category. I'm populating a multi-dimensional array from a recordset, and it works absolutely fine with my test data. I have several different recordsets which contain various numbers of records, some over a hundred, some with none at all. Every recordset which contains none or more than one works absolutely fine, it's just the scenario where there is just one record.
In this scenario, the second column cannot be populated for some reason, and I am given a subscript out of range error message. Here is my code:
Code:
If rstRecordSet.EOF = False Then
varRecCnt = rstRecordSet.RecordCount
ReDim Paths(1 To varRecCnt, 1 To varRecCnt)
rstRecordSet.MoveFirst
Do
Paths(rstRecordSet.AbsolutePosition, 1) = rstRecordSet.Fields(0)
Paths(rstRecordSet.AbsolutePosition, 2) = rstRecordSet.Fields(1)
rstRecordSet.MoveNext
Loop Until rstRecordSet.EOF = True
rstRecordSet.Close
Else
MsgBox "No records were returned using the query " & cmdCommand.CommandText
End If
Thanks for any help you can offer,
Matthew