
Subscript out of range Error when using Arrays
Hi all,
I keep getting a Error "Subscript out of range" Runtime error 9?
please help??? I think it is related to one of the Arrays
Dim RsCSV As New ADODB.Recordset
Dim Lines() As String, fields() As String
Dim i As Long, j As Long
Dim path As String
Dim strToFind As String
strToFind = """"
strDelim = Chr$(cmbDelimiter.ItemData(cmbDelimiter.ListIndex))
Screen.MousePointer = vbHourglass ' Change mouse pointer to hourglass.
Open ComDial1.FileTitle For Input As #1
'Read the contents of the file, and process each individual line.
Lines() = Split(Input(LOF(1), 1), vbCrLf)
Close #1
'Process the first line, which contains the list of fields.
fields() = Split(Lines(0), strDelim)
For j = 0 To UBound(fields)
RsCSV.fields.Append fields(j), adChar, 200
Next
RsCSV.Open
ReDim FieldNames(0 To fieldMax) As Variant
For j = 0 To fieldMax
FieldNames(j) = fields(j)
Next
For i = 1 To UBound(Lines)
'Modify Data as it is put in array,removed here because needed to
search entire file
'fields() = Split((Replace(Lines(i), strToFind, "")), strDelim) '
Remove all "
fields() = Split(Lines(i), strDelim)
ReDim fieldValues(0 To fieldMax) As Variant
For j = 0 To UBound(fields)
fieldValues(j) = fields(j) 'Move values into the Variant
Array.
Next
RsCSV.AddNew FieldNames(), fieldValues()
Next
RsCSV.MoveFirst
Set DataGrid1.DataSource = RsCSV
Screen.MousePointer = vbDefault ' Return mouse pointer to normal.