Importing From Txt File

dansalmada

Registered User.
Local time
Today, 10:58
Joined
Jun 7, 2004
Messages
16
Hello,

I need to import (or link) a txt file into Access but the file has hard breaks or "  " symbols. Access only imports the lines up until the first hard break, (the file has many of these).

What can I do so the file is linked or imported completely???

Thanks
Daniel
 
Daniel,

Can you post a small sample of the file, along with your table structure?

Wayne
 
WayneRyan said:
Daniel,

Can you post a small sample of the file, along with your table structure?

Wayne



Wayne, Here is an attachment of how my file looks. I have several of those breaks whre the word "COIL" appears on the first line.

Thanks
 

Attachments

Daniel,

It looks like you just get an occasional "non-printable"
character in your data. If you can't control it at the
source (when they generate the file), you'll have to
fix it afterwards.

Something like the following should work. I just used
values 32 & 127 because they're the normal range of
printable characters.

Code:
Dim Buffer As String
Dim Temp As String
Dim i As Long

Open "C:\Sample.txt" For Input as #1
Open "C:\SampleNew.txt" For Output as #1

Line Input #1, Buffer
While Not EOF(1)
   Temp = ""
   For i = 1 to Len(Buffer)
     If Asc(Mid(Buffer, i, 1)) Between 32 And 127 Then
        Temp = Temp & Mid(Buffer, i, 1)
     Next i
   Print #2, Temp
   Line Input #1, Buffer
   Wend
Close #1
Close #2

Now, IF the inadvertant characters are record terminators (carriage-return,
line-feed) then it will screw the Linput statement up just like it does when
you import it. THEN, you'll need to either correct it beforehand, or write
code to traverse the file in binary.

Let me know,
Wayne
 

Users who are viewing this thread

Back
Top Bottom