Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / February 2005

Tip: Looking for answers? Try searching our database.

How to merge 2 txt files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dirk - 04 Feb 2005 10:37 GMT
Hi,

Hope anybody can help me.
Created 2 tabels via append query's and export limited the content to two
text files.
Both txt files have differtent content and export specs.
Now I must merge 2 files. Normally now problem to put 2 files below eachother.
I must merge line under line.
Report can contain upto 500 lines per txt file.

Tx,
Dirk
John Nurick - 05 Feb 2005 13:23 GMT
Hi Dirk,

If you want to create one file that contains the contents of the first
file followed by the contents of the second, just construct a Windows
command like this

COPY "C:\folder\first file.txt" + "C:\folder\Second file.txt"
"C:\folder\combined file.txt"

and then use the Shell() command to execute it.

If you want to interleave the contents, it's usually best to create an
Access query that produces the results you need.

>Hi,
>
[quoted text clipped - 8 lines]
>Tx,
>Dirk

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Dirk - 07 Feb 2005 09:45 GMT
Hi John,

Thanks for your help.
Problem is not solved yet. Big point is the complete diff. export specs per
file. These are limited.
File contains;
Headers, no problem
Line1 file 1
Line1 file 2
Line2 file 1
Line2 file 2
etc.
Footer, no problem

File 1 specs:
Field 1, start 1 width 3
Field 2, start 4, width 3
Field 3, start 7, width 40
Field 4, start 47, width 40
Upto field 82 endwidth 1223

File 2 specs:
Field 1, start 1 width 3
Field 2, start 4, width 8
Field 3, start 12, width 12
Field 4, start 24, width 20
Upto field 16 endwidth 229

When i merge the two query's first via a apendquery into one table and
export the table as far as I know I can only use one export spec.
Now we export both files and copy/past all lines together.
Our customer we send the file to is a big international company otherwise I
had ask them to change their input.

BR,
Dirk

> Hi Dirk,
>
[quoted text clipped - 27 lines]
>
> Please respond in the newgroup and not by email.
John Nurick - 07 Feb 2005 22:06 GMT
Hi Dirk,

There are several ways to go. Here are a couple:

1) export the two files as now, then run a script (outside Access) to
interleave them. Here's a Perl script that does the job; you can do the
same thing (if less compactly) in VBScript or other languages:

#Perl script to interleave text files line by line
use strict;
die "Usage:\n  perl interleave.pl file1 file2 outfile\n"
 unless $ARGV[2];
open IN1, $ARGV[0] or die "Sorry, couldn't open $ARGV[0]. ";
open IN2, $ARGV[1] or die "Sorry, couldn't open $ARGV[1]. ";
open OUT, ">$ARGV[2]" or die "Sorry, couldn't create $ARGV[2].";

my ($in1, $in2);
print OUT "$in1$in2" while (($in1 = <IN1>) && ($in2 = <IN2>));
#end of script

2) In Access VBA, open a recordset on each query and a single textfile,
then assemble and write a line from each recordset in turn. Pseudocode:

Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset

Set rst1 = DBEngine(0)(0).OpenRecordset(blah blah)
Set rst2 = DBEngine(0)(0).OpenRecordset(blah blah)
Open "C:\folder\file.txt" For Output As #1

Do Until (rst1.Eof Or rst2.Eof)
 With rst1
   strLine = Format(.Fields(1), "blah") _
     & Format(.Fields(2) "blah" _
     ....
     #assemble a string containing the record you want to write
   Print #1, strLine
 End With
 With rst2
   ...
 End With
 rst1.MoveNext
 rst2.MoveNext
Loop
Close #1
rst1.Close
rst2.Close

>Hi John,
>
[quoted text clipped - 64 lines]
>>
>> Please respond in the newgroup and not by email.

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.