Import using Split Function

L

LeAnn

After reading several post I decided to try use the split function to import
data from my comma delimited text files. I was using the TransferText method
which works like a charm except that I need to add custom field data for each
record. Can I do that using the TransferText metihod?

I am trying to use the split function but some of the fields have
qualifiers. How or do I deal with those using the split function? After
testing the code below, I'm getting a "Data type converstion" error on the
first field assignment.

Ok now after debug.print strLine I see that it prints 4 records. It seems
to me that it isn't reading where the end of line occurs?? Also, I don't
understand arrays very well so I'm sure I don't have that set up correctly
yet. The Ubound is returning 0.

Code snip

lngFN = FreeFile()
Open strPath For Input As #lngFN

Set rst = db.OpenRecordset(strTable)

Do Until EOF(lngFN)
rst.AddNew 'create new record
Line Input #lngFN, strLine
Debug.Print strLine
varRecordArray = Split(strLine, "'", 1)
rst.AddNew
rst.Fields("Field1") = CLng(varRecordArray(0))
rst.Fields("Field2") = varRecordArray(1)
rst.Fields("Field3") = varRecordArray(2)
rst.Fields("Field4") = varRecordArray(3)
rst.Fields("Field5") = varRecordArray(4)
rst.Fields("Field6") = varRecordArray(5)
.........26 fields
rst.Fields("Field27") = strInstr
rst.Update
Loop

Thanks
LeAnn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top