Importing Text file without carriage return

CravenStu

New member
Local time
Today, 03:54
Joined
Jun 12, 2003
Messages
6
I am trying to import a large text file into Access97, but it is treating the whole text file as one line.

I think there are no carriage return in the text file.

It is a huge file, so is there an easy way of importing the file.
 
Import it into a memo field and the parse it to whatever recorglength you want into a new table of fixed record length.
 
You need to know why the records are lumped together.

You MIGHT try importing it to WORD to see if it has something embedded that signifies the end of a line. If, for example, it is a raw data stream with embedded <CR> and <LF>, you might choose to save the file in a different format, say ANSI Text.

If WORD won't take it, either, I don't know where to go from there except to write a parser OR write some VBA code that opens the file, splits it into records, and appends to a VBA recordset.
 
CravenStu,

Haven't tried it, but something like this should
get you started. If you do this often, you should get them to
format the file a little more nicely for you.

Code:
Type Record 
    tblData As String * 100 ' Length of record
End Type

Dim MyRecord As Record
Dim i As Long
Dim dbs As Database
Dim rst As Recordset

Open "C:\Testfile.dat" For Random As #1 Len = Len(MyRecord)

Set dbs = CurrentDb
Set rst = db.OpenRecordSet("YourTable")

i = 1
Get #1, i, MyRecord
While Not EOF(1)
  rst.AddNew
  rst!Field1 = Mid(MyRecord.tblData, 1, 10) ' do for each field
  rst!Field2 = Mid(MyRecord.tblData, 10, 10)
  rst.Update
  i = i + 1
  Get #1, i, MyRecord
  Wend
Close #1    ' Close file.

Wayne
 

Users who are viewing this thread

Back
Top Bottom