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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help loading data into Array

Status
Not open for further replies.

Dijital

MIS
Mar 15, 2002
47
US
I have a database (access 2k) of filenames, version, and path, that I need to test for on each PC I support. so I loaded the SQL results into rsRequired. I then, using someones example put in the following sub:

Sub GetRequired

Dim lngCounter
Dim rsRequired
Dim cnMSOffice

' Create the connection object and connection string, then open the connection
Set cnMSOffice = CreateObject("ADODB.Connection")

cnMSOffice.ConnectionString = "provider=Microsoft.JET.OLEDB.4.0;User ID=Admin;Data Source=\\njwarfs7\sms_pkg$\utils\MSOff2000.mdb"

cnMSOffice.Open

'create the recordset object
Set rsRequired = cnMSOffice.Execute("SELECT FILES.FILE_NAME, FILES.VERSION, FILES.PATH, FILES.REQUIREDID FROM REQUIRED INNER JOIN FILES ON REQUIRED.ID = FILES.REQUIREDID WHERE (((REQUIRED.REQUIRED)=Yes));")

'code ok to here

ReDim astrFileList(version,0)
lngCounter = 0
Do While Not rsRequired.EOF
ReDim Preserve astrPhoneList(version, lngCounter)

astrFileList(version, lngCounter) = rsRequired.Fields("VERSION").Value
astrFileList(file_name, lngCounter) = rsRequired.Fields("FILE_NAME").Value
astrFileList(path, lngCounter) = rsRequired.Fields("PATH").Value

lngCounter = lngCounter + 1
rsRequired.MoveNext
Loop
End Sub

The error I'm getting is "subscript out of range" at the first loading line (astrFileList(version, lngCounter) = rsRequired.Fields("VERSION").Value) the value is 1.

I'm guessing that the "ReDim astrFileList(version,0)" the second parameter is how many records, am I right? IF so, then when I try the second set, the "subscript" error will pop up becuase I have only allowed for 0. What if I dont know how many there will be?

Any help would be great - this is the first time I've ever written anything like this.

-Jim Connors
 
Do the following:

Do While Not rsRequired.EOF
astrFileList(version, lngCounter) = rsRequired.Fields("VERSION").Value
astrFileList(file_name, lngCounter) = rsRequired.Fields("FILE_NAME").Value
astrFileList(path, lngCounter) = rsRequired.Fields("PATH").Value

rsRequired.MoveNext

if not rsRequired.eof then
lngCounter = lngCounter + 1
ReDim Preserve astrPhoneList(version, lngCounter)
end if

Loop
End Sub
"did you just say Minkey?, yes that's what I said."

MrGreed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top