Discussion Locked

Array Declaration in VB 6.0

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

When I try to specify the upperbound of strValues by referencing tempRS's record count property I get a subscript out of range error. Any suggestions?

Dim tempRS As Recordset
Dim intUpperbound As Integer
Dim i As Integer
Dim strValues() As String
Dim strSQL As String
Set tempRS = New Recordset
strSQL = "SELECT tblContacts.CAddress FROM tblContacts;"
tempRS.Open strSQL, CN, adOpenDynamic, adLockOptimistic
ReDim strValues(0 To tempRS.RecordCount - 1) As String

4 replies

by afisher

Also, the SQL statement runs fine in Access (my back end) and the connection is open and working fine when referenced by other procedures.

by mpalazzo

What's the value of your tempRS.RecordCount? I'll bet it's -1 which would indicate that the record count property is unavailable due to either your cursor type (which looks okay to me) or the data provider not being able to return the number of records. One solution might be to open the rs before you redim the array, move to the last record and then store the absolute record position in a variable (long). Then just redim your array using the variable as the ubound instead of using the recordcount property.

Did that help? :)

This discussion is closed to new replies.