Importing a Text File with long rows

  • Thread starter Thread starter R Bolling
  • Start date Start date
R

R Bolling

I have a text file where each row comprises an entire paragraph.
Importing into a memo file still cuts off the data both using File -
Get External Data or importing via Transfer Text. I would like to try
a code approach to this.

Here is a problem scenario:

Text file: MyTextFile.txt

This is some example text. This is some example text. . .
This is some more sample text. This is some more sample text. . .
This is another line of sample text. . .
..
..
..

Database: MyDB.mdb

Table: MyTbl (2 Fields)
ID: Autonumber
Memo1: Memo

What is a method using code to append this text into MyTbl?

Thank you for any assistance with this

Robby
 
Open a recordset based on the table and append the data as you read it to
the table. Something like this, perhaps:


Dim rst As DAO.Recordset, dbs As DAO.Database
Dim strLine As String

Open "C:\MyTextFile.txt" For Input As #1

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("MyTbl", dbOpenDynaset, dbAppendOnly)

Do While EOF(1) = False
Line Input #1, strLine
rst.AddNew
rst.Fields("Memo1").Value = strLine
rst.Update
Loop

rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
Close #1
 
If the paragraphs are longer than 64K,
Open the file as binary, with 32K character records,
use AppendChunk to add the chunk to the memo field.
 
Back
Top