Importing a Text File with long rows

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
 
K

Ken Snell

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
 
D

david epsom dot com dot au

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.
 

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