Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

merge files in VBA

Status
Not open for further replies.

rorymurray

Programmer
Oct 16, 2001
44
AU
I have used Access to create 3 separate text files.

Now I want to append all the data from the 3 files into 1 file, bit like a union query in Access.

Any ideas on how to go about it?

Rory
 
Hi

If you mean append then you:

(in pseudo code)open an output file
for i =1 to 3
open file i
read until eof
write to outputfile
next inputfile
close output

but if you mean mean as in some particular order then I would suggest the easiest way is read into a table, then run a query on the table ordering by whatever, then export to a text file (see Docmd.transfertext)
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
That looks right. Any idea on the VBA syntax?

I gave up on the idea of trying to put it all into a table because the records are of different types and are quite long (ie >300 characters), and Access likes to chop off anything in a field that is longer than 256 characters when exporting.
 
Hi

I do not use text files very often, so no promises, but here goes

Dim lngFileI as Long
Dim lngFileO as Long

lngFileO = FreeFile()
Open "FileName" For Output as #lngFileO
For i = 1 To 3
lngFileI = FreeFile()
Open "FileName" & i For Input As #lngFileI
Line Input A$
Do Until EOF(lngFileI)
Print #lngFileO, a$

Line Input a$
If Eof(lngFileI) Then
Exit Loop
End If
Loop
Close #lngFileI
Next i
Close #ngFileO

As I said no promises, but its hould not be far wrong Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top