Dim i As Integer
Do Until EOF(1)
xchar = Input(1, #1) 'Get one character
If xchar = vbLf Then 'Linefeed end of current record, process the transfer of data in to the table
reccount = reccount + 1 'counts the number of records to ensure we actually get to the end of the file
fieldcount = 1 'reset the count of how many fields have been processed
reclength = 0 ' was used to measure the length of the record can be removed
'MsgBox reccount for testing no longer needed
'GoTo skip for testing no longer needed
If reccount > 1 Then ' process if not heading record
With rst ' process first table
.AddNew
For i = 1 To 200 ' count fields
.Fields(i) = fieldstring(i) 'set table field to constructed array string (i)
fieldstring(i) = "" 'resets all the fields back to nothing
Next i
.Update
End With
With rst2 'process second table
.AddNew
.Fields(63) = keyfield 'set primary key in tblImport2
For i = 1 To maxfields - 200 'write records to remaining fields stored in tbl2
.Fields(i) = fieldstring(i + 200) 'set table field to constructed array string (i plus the 200 already prcessed)
fieldstring(i + 200) = "" ' reset all the fields back to nothing
Next i
.Update
End With
End If
'skip: no longer used
Else ' if no linefeed has been found add the single characters to the current array for the current record
If reccount > 0 Then
x = x + 1
If xchar = Chr(34) Then 'test for a quote inside the array
If first = 0 Then ' has the "first quote" flag already been set which means the quotes have now been opened ignore following commas
first = 1 'if it has not been set then set it
Else ' so the first quote flag has been set so reset it back to zero, this means the quote in the current array is closing the quotes process the following commas
first = 0
End If
'MsgBox x was used to count character not needed
End If
'MsgBox x & " " & fieldcount & " - " & "first - " & first display processing data not needed
If first = 1 Then ' quotes are now open ignore comma which is a Field Seperator
fieldstring(fieldcount) = fieldstring(fieldcount) & xchar ' add character to the current array
Else ' quotes not opened so take in to account commas
If xchar <> "," Then fieldstring(fieldcount) = fieldstring(fieldcount) & xchar 'add character if not a comma, ie end of current field
If xchar = "," And first = 0 Then ' if it is a comma and quotes are not open the increement the array counter
fieldcount = fieldcount + 1 'increement the array counter
If fieldcount = 25 Then keyfield = fieldstring(24) ' if the number of fields is now 25 it means the previous field was the keyfield so set a string with it's value
End If
End If
End If
maxfields = fieldcount ' store the number of fields process no longer needed
End If