Import text file problem; combine lines?

hobbes

Registered User.
Local time
Today, 00:44
Joined
Feb 13, 2004
Messages
30
Is it possible to combine two lines in a text file to one row/record in an Access database? The import wizard allows me to set my columns, but I cannot create proper columns because my data imports into two rows in a table. Having information on two rows that do not line up make it impossible to capture all of the information that I need. The file I am trying to import is extremely large (millions of rows), so manually changing the rows in the text file is not an option. Any help would be great!
 
You can probably achieve this in a number of ways. One way might be to have a vba loop.

But if you´re not used to that (I noticed you are a new member), maybe you could do it with a word macro?

How are you planning to know which row should go with which? Do they always come in pairs so that row2 should be on row1 and row4 on row3?

Fuga.
 
hobbes,

If you can post a sample of the data, and your table structure.
I'll take a shot at it.

Wayne
 
Fuga,

You are correct in assuming I am new to vba loops and macros. To answer your question, yes, the rows always come in pairs where row2 should be at the end of row1, row 4 at the end of row3, etc.
I have another question regarding using Microsoft Word for this task. Will Word have the capacity to hold millions of lines in a single document? Do I run the risk of losing information from the second line, once they are combined, from Word not having enough room to display the information on a single line?

Wayne,
I am putting together a bit of sample data and will post it very soon.

THANK YOU both VERY much for all of your help with this!!!

Hobbes
 
Here´s something I fooled around with. This will combine the lines and save them in another text file. I´m sure there are better ways, but here we go.

Be sure you have backup of your data. I just tried it with a few numbers, I don´t know what will happen with millions of text lines.

Firstfile = your text file
secondfile = the text file you want your combined data in.
Code:
Sub textlines()
Dim Firstline, secondline
Dim iTG As Integer
Open "c:\firstfile.txt" For Input As #1
Open "c:\secondfile.txt" For Output As #2
iTG = 1
Do While Not EOF(1)
    Line Input #1, secondline
        If iTG = 1 Then
        Firstline = secondline
        iTG = 3
        End If
        If iTG = 2 Then
        Print #2, Firstline & " " & secondline
        iTG = 1
        End If
        If iTG = 3 Then
        iTG = 2
        End If
Loop
Close #1
Close #2
End Sub

Fuga.
 
Did it work?

I´m a bit curious myself.

Fuga.
 
Thank you!

I wanted to let you know that I got it to work. I had to do some tweeking to get it to tailor it to my text file, but it works! Thank you so much for your help!!! :D
 

Users who are viewing this thread

Back
Top Bottom