Two approaches come to mind.
(1) Run a VBA procedure that modifies the text files by combining the data
from every three-line section and writing it into new text file. Then import
the new text file.
(2) Import the data using VBA code by opening the text file, reading the
three-line segment, and writing it directly into a recordset that is bound
to the data table.
Which would you prefer?
Thanks for getting back with me. Option # 1 sounds the
best. Unfortunately, I might be beyond my skill set at
this time, but I'm willing to give it a try.
Thanks again.
>-----Original Message-----
>Two approaches come to mind.
[quoted text clipped - 37 lines]
>
>.
Nikos Yannacopoulos - 31 Aug 2004 08:08 GMT
Gary,
Here is some sample code to implement Option 1:
Sub Manipulate_Text()
Dim SourceFile As Text
Dim DestFile As Text
Dim readline As Text
Dim newline As Text
SourceFile = "C:\SomeFolder\SomeFile.txt"
DestFile = "C:\SomeFolder\NewFile.txt"
Open SourceFile For Input As #1
Open DestFile For Output As #2
Do Until EOF(1)
For i = 1 To 3
Line Input #1, readline
If newline <> "" Then newline = newline & ","
newline = newline & readline
Next
Write #2, newline
newline = ""
Loop
Close #2
Close #1
End Sub
A different approach would be to manipulate the file in Excel: import the
text file (in one column), move the imported column to B. use column A to
mark every third line, then copy column B to columns C and D, delete /shift
up C1 and D1:D2, so every third column has a full record. Sort on column A
to get all the full records together, and delete the rest.
HTH,
Nikos
> Thanks for getting back with me. Option # 1 sounds the
> best. Unfortunately, I might be beyond my skill set at
[quoted text clipped - 52 lines]
> >
> >.
Ken Snell [MVP] - 31 Aug 2004 19:11 GMT
Here's some code to read one text file and write out every three-line block
as one new record in a new text file:
Dim strFileIn As String, strFileOut As String, strLine As String
Dim strNewLine As String
Dim intCount As Integer
' Path and file of text file being read/converted
strFileIn = "C:\MyFolder\TextFileName.txt"
' Path and file of text file being created
strFileOut = "C:\MyFolder\NewTextFileName.txt"
Open strFileIn For Input As #1
Open strFileOut For Output As #2
intCount = 0
strNewLine = ""
Do While EOF(1) = False
Line Input #1, strLine
intCount = intCount + 1
' Combine the line with the other lines of a group,
' using pipe character "|" as the delimiter
strNewLine = strNewLine & strLine & "|"
' If this is the third line of a group, write it out
' to the new file and reset the counter
If intCount = 3 Then
Print #2, strNewLine
strNewLine = ""
End If
Loop
Close #1
Close #2

Signature
Ken Snell
<MS ACCESS MVP>
> Thanks for getting back with me. Option # 1 sounds the
> best. Unfortunately, I might be beyond my skill set at
[quoted text clipped - 52 lines]
> >
> >.