Appending Text file with a header record | | |
I have a data application in a2k that I need to create two fixed width
text files and then combine them to a single file The first file is
header information and the second is transaction data. I have tried
and tried but just cant seem to get this right, I am using Queries to
created my export files with specifications which works fine, I get
stumped with the appending the header to my transaction file. What I
have so far looks like this .. What I wind up in my file is,
1 2003100713250020441007
"c:\Trans.Txt"
What I need to know is how to declare the c:\trans.txt so it will
append data and not the string
Any help would be great!
Thanks
Michael
+++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub Command0_Click()
Dim strFirstQuery As String
Dim strSecondQuery As String
Dim strPath As String
Dim strPath1 As String
strPath = "c:\Header.txt" 'Header Information file
strPath1 = "c:\Trans.Txt" 'Transactions file
strFirstQuery = "QryHeader"
strSecondQuery = "QryTransactions"
'Output Transaction Header
DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
'OutPut Transactions
DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
Open strPath For Append As #1
Write #1, strPath1
Close #1
End sub | | | | re: Appending Text file with a header record
The variable strPath1 is holding the name and path of the file, not the file itself, so
that is what is being appended. To append the data from the file, you will need to open
the file and use a Get statement to read the file and then append that data. You could use
a Do loop to run the read/append until EOF.
In the second TransferText call, what would happen if instead acExportFixed you used
acExportMerge, I don't see a good explanation of what each of these constants do.
--
Wayne Morgan
"Michael" <Mikch_49@HotMail.Com> wrote in message
news:43e38787.0310091233.3a99afd1@posting.google.c om...[color=blue]
> I have a data application in a2k that I need to create two fixed width
> text files and then combine them to a single file The first file is
> header information and the second is transaction data. I have tried
> and tried but just cant seem to get this right, I am using Queries to
> created my export files with specifications which works fine, I get
> stumped with the appending the header to my transaction file. What I
> have so far looks like this .. What I wind up in my file is,
>
> 1 2003100713250020441007
> "c:\Trans.Txt"
>
> What I need to know is how to declare the c:\trans.txt so it will
> append data and not the string
>
> Any help would be great!
>
> Thanks
>
> Michael
>
> +++++++++++++++++++++++++++++++++++++++++++++++++
>
> Private Sub Command0_Click()
>
> Dim strFirstQuery As String
> Dim strSecondQuery As String
> Dim strPath As String
> Dim strPath1 As String
>
>
>
>
>
> strPath = "c:\Header.txt" 'Header Information file
> strPath1 = "c:\Trans.Txt" 'Transactions file
> strFirstQuery = "QryHeader"
> strSecondQuery = "QryTransactions"
>
> 'Output Transaction Header
> DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
> 'OutPut Transactions
> DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
>
> Open strPath For Append As #1
> Write #1, strPath1
> Close #1
>
> End sub[/color] | | | | re: Appending Text file with a header record Mikch_49@HotMail.Com (Michael) wrote in message news:<43e38787.0310091233.3a99afd1@posting.google. com>...[color=blue]
> I have a data application in a2k that I need to create two fixed width
> text files and then combine them to a single file The first file is
> header information and the second is transaction data. I have tried
> and tried but just cant seem to get this right, I am using Queries to
> created my export files with specifications which works fine, I get
> stumped with the appending the header to my transaction file. What I
> have so far looks like this .. What I wind up in my file is,
>
> 1 2003100713250020441007
> "c:\Trans.Txt"
>
> What I need to know is how to declare the c:\trans.txt so it will
> append data and not the string[/color]
I think the problem is that you may need to output the two queries to
text first. Then you can open one for append and the other for read.
Read each line of the first and write it to the second. then you
should be off an running... I'm kinda wondering if you can't use
SPACE(intSpaces) to create your own delimited text file, because then
you can just open a text file, loop through the records in your
query's recordset, write the records to the file, close the first
query, open the second, repeat the output stuff, and then append the
path or whatever just using a write statement... I think this is just
a limitation of the TransferText method - it assumes one output file
per object. | | | | re: Appending Text file with a header record
What would happen if your output query was a Union query, combining both outputs into one
query?
--
Wayne Morgan | | | | re: Appending Text file with a header record
Wayne,
Your first idea is exactly what I need to do, though I am unclear how
to write the code to accomplish this. I have the two files outputting
correctly, I just need to append the first (header.txt) to the second
(trans.txt) Do you think you could provide an example?
Thanks for your help,
Michael
"Wayne Morgan" <comprev_gothroughthenewsgroup@hotmail.com> wrote in message news:<hOohb.11880$iw7.8064@newssvr32.news.prodigy. com>...[color=blue]
> The variable strPath1 is holding the name and path of the file, not the file itself, so
> that is what is being appended. To append the data from the file, you will need to open
> the file and use a Get statement to read the file and then append that data. You could use
> a Do loop to run the read/append until EOF.
>
> In the second TransferText call, what would happen if instead acExportFixed you used
> acExportMerge, I don't see a good explanation of what each of these constants do.
>
> --
> Wayne Morgan
>
>
> "Michael" <Mikch_49@HotMail.Com> wrote in message
> news:43e38787.0310091233.3a99afd1@posting.google.c om...[color=green]
> > I have a data application in a2k that I need to create two fixed width
> > text files and then combine them to a single file The first file is
> > header information and the second is transaction data. I have tried
> > and tried but just cant seem to get this right, I am using Queries to
> > created my export files with specifications which works fine, I get
> > stumped with the appending the header to my transaction file. What I
> > have so far looks like this .. What I wind up in my file is,
> >
> > 1 2003100713250020441007
> > "c:\Trans.Txt"
> >
> > What I need to know is how to declare the c:\trans.txt so it will
> > append data and not the string
> >
> > Any help would be great!
> >
> > Thanks
> >
> > Michael
> >
> > +++++++++++++++++++++++++++++++++++++++++++++++++
> >
> > Private Sub Command0_Click()
> >
> > Dim strFirstQuery As String
> > Dim strSecondQuery As String
> > Dim strPath As String
> > Dim strPath1 As String
> >
> >
> >
> >
> >
> > strPath = "c:\Header.txt" 'Header Information file
> > strPath1 = "c:\Trans.Txt" 'Transactions file
> > strFirstQuery = "QryHeader"
> > strSecondQuery = "QryTransactions"
> >
> > 'Output Transaction Header
> > DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
> > 'OutPut Transactions
> > DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
> >
> > Open strPath For Append As #1
> > Write #1, strPath1
> > Close #1
> >
> > End sub[/color][/color] | | | | re: Appending Text file with a header record
Try this, some of it will depend on the way your data is formatted. This can be adjusted
to read specific record lengths, put quotes around text or not put quotes (use Print
instead of Write), etc. I currently have it reading one line at a time.
Private Sub Command0_Click()
Dim strFirstQuery As String
Dim strSecondQuery As String
Dim strPath As String
Dim strPath1 As String
Dim strData As String
strPath = "c:\Header.txt" 'Header Information file
strPath1 = "c:\Trans.Txt" 'Transactions file
strFirstQuery = "QryHeader"
strSecondQuery = "QryTransactions"
'Output Transaction Header
DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
'OutPut Transactions
DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
Open strPath1 For Append Access Write As #1
Open strPath2 For Binary Access Read As #2
Do
Line Input #2, strData
Write #1, strData
Loop Until EOF(2)
Close #1
Close #2
End sub
--
Wayne Morgan
"Michael" <Mikch_49@HotMail.Com> wrote in message
news:43e38787.0310100743.738fc1f8@posting.google.c om...[color=blue]
> Wayne,
>
> Your first idea is exactly what I need to do, though I am unclear how
> to write the code to accomplish this. I have the two files outputting
> correctly, I just need to append the first (header.txt) to the second
> (trans.txt) Do you think you could provide an example?[/color] | | | | re: Appending Text file with a header record
"Wayne Morgan" <comprev_gothroughthenewsgroup@hotmail.com> wrote in message news:<Uayhb.15516$Ro2.3674@newssvr31.news.prodigy. com>...[color=blue]
> What would happen if your output query was a Union query, combining both outputs into one
> query?[/color]
If I create a Join Query the Header shows up in every Record. I need
the Header to appear at the top of the text file and also a Trailer at
t he bottom of the file. | | | | re: Appending Text file with a header record
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++
Wayne,
This seems to work, however I am getting a Run Time error '62' Imput
Past end of file, and it is putting quotes around my Transactions in
the merged file. Below is a sample of the output and the finished
code I am using.
Thanks again for all your help!
This is a sample of the out put, which is perfect except for the
quotes
1 2003100713250020441007
"OHD773050105220030927"
"OHD773051105220030927"
"OHD773052105220030927"
This is the finished code ..
Private Sub Command0_Click()
Dim strFirstQuery As String
Dim strSecondQuery As String
Dim strPath As String
Dim strPath1 As String
Dim strData As String
strPath = "c:\Header.txt" 'Header Information file
strPath1 = "c:\Trans.Txt" 'Transactions file
strFirstQuery = "QryHeader"
strSecondQuery = "QryTransactions"
'Output Transaction Header
DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
'OutPut Transactions
DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
Open strPath For Append Access Write As #1
Open strPath1 For Binary Access Read As #2
Do
Line Input #2, strData
Write #1, strData
Loop Until EOF(2)
Close #1
Close #2
End Sub
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
"Wayne Morgan" <comprev_gothroughthenewsgroup@hotmail.com> wrote in message news:<VEChb.3906$q72.3174@newssvr17.news.prodigy.c om>...[color=blue]
> Try this, some of it will depend on the way your data is formatted. This can be adjusted
> to read specific record lengths, put quotes around text or not put quotes (use Print
> instead of Write), etc. I currently have it reading one line at a time.
>
>
> Private Sub Command0_Click()
>
> Dim strFirstQuery As String
> Dim strSecondQuery As String
> Dim strPath As String
> Dim strPath1 As String
> Dim strData As String
>
> strPath = "c:\Header.txt" 'Header Information file
> strPath1 = "c:\Trans.Txt" 'Transactions file
> strFirstQuery = "QryHeader"
> strSecondQuery = "QryTransactions"
>
> 'Output Transaction Header
> DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
> 'OutPut Transactions
> DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
>
>
> Open strPath1 For Append Access Write As #1
> Open strPath2 For Binary Access Read As #2
>
> Do
> Line Input #2, strData
> Write #1, strData
> Loop Until EOF(2)
>
> Close #1
> Close #2
>
> End sub
>
>
> --
> Wayne Morgan
>
>
> "Michael" <Mikch_49@HotMail.Com> wrote in message
> news:43e38787.0310100743.738fc1f8@posting.google.c om...[color=green]
> > Wayne,
> >
> > Your first idea is exactly what I need to do, though I am unclear how
> > to write the code to accomplish this. I have the two files outputting
> > correctly, I just need to append the first (header.txt) to the second
> > (trans.txt) Do you think you could provide an example?[/color][/color] | | | | re: Appending Text file with a header record Mikch_49@HotMail.Com (Michael) wrote in message news:<43e38787.0310130701.2452a6d9@posting.google. com>...[color=blue]
> ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++
> Wayne,
>
> This seems to work, however I am getting a Run Time error '62' Imput
> Past end of file, and it is putting quotes around my Transactions in
> the merged file. Below is a sample of the output and the finished
> code I am using.
>
> Thanks again for all your help!
>
> This is a sample of the out put, which is perfect except for the
> quotes
>
> 1 2003100713250020441007
> "OHD773050105220030927"
> "OHD773051105220030927"
> "OHD773052105220030927"
>
> This is the finished code ..
>
> Private Sub Command0_Click()
> Dim strFirstQuery As String
> Dim strSecondQuery As String
> Dim strPath As String
> Dim strPath1 As String
> Dim strData As String
>
> strPath = "c:\Header.txt" 'Header Information file
> strPath1 = "c:\Trans.Txt" 'Transactions file
> strFirstQuery = "QryHeader"
> strSecondQuery = "QryTransactions"
>
>
> 'Output Transaction Header
> DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
> 'OutPut Transactions
> DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
>
>
>
> Open strPath For Append Access Write As #1
> Open strPath1 For Binary Access Read As #2
>
> Do
> Line Input #2, strData
> Write #1, strData
> Loop Until EOF(2)
>
> Close #1
> Close #2
> End Sub
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++[/color]
Do Until EOF(2)
Line Input #2, strData
Write #1, strData
Loop
Close #1
Close #2
You just need to test for EOF first, I think. Of course, you have to
make sure then that you get the last record in textfile #1 into #2. | | | | re: Appending Text file with a header record
I don't know how to get rid of the quotes, I had to get this far through trial and error
and reading the not so informative help file. Perhaps, if you seek to the end of file #1
then do a Binary write to the file?
--
Wayne Morgan
"Michael" <Mikch_49@HotMail.Com> wrote in message
news:43e38787.0310130701.2452a6d9@posting.google.c om...[color=blue]
> ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++
> Wayne,
>
> This seems to work, however I am getting a Run Time error '62' Imput
> Past end of file, and it is putting quotes around my Transactions in
> the merged file. Below is a sample of the output and the finished
> code I am using.
>
> Thanks again for all your help!
>
> This is a sample of the out put, which is perfect except for the
> quotes
>
> 1 2003100713250020441007
> "OHD773050105220030927"
> "OHD773051105220030927"
> "OHD773052105220030927"
>
> This is the finished code ..
>
> Private Sub Command0_Click()
> Dim strFirstQuery As String
> Dim strSecondQuery As String
> Dim strPath As String
> Dim strPath1 As String
> Dim strData As String
>
> strPath = "c:\Header.txt" 'Header Information file
> strPath1 = "c:\Trans.Txt" 'Transactions file
> strFirstQuery = "QryHeader"
> strSecondQuery = "QryTransactions"
>
>
> 'Output Transaction Header
> DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
> 'OutPut Transactions
> DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
>
>
>
> Open strPath For Append Access Write As #1
> Open strPath1 For Binary Access Read As #2
>
> Do
> Line Input #2, strData
> Write #1, strData
> Loop Until EOF(2)
>
> Close #1
> Close #2
> End Sub
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
>
>
> "Wayne Morgan" <comprev_gothroughthenewsgroup@hotmail.com> wrote in message[/color]
news:<VEChb.3906$q72.3174@newssvr17.news.prodigy.c om>...[color=blue][color=green]
> > Try this, some of it will depend on the way your data is formatted. This can be[/color][/color]
adjusted[color=blue][color=green]
> > to read specific record lengths, put quotes around text or not put quotes (use Print
> > instead of Write), etc. I currently have it reading one line at a time.
> >
> >
> > Private Sub Command0_Click()
> >
> > Dim strFirstQuery As String
> > Dim strSecondQuery As String
> > Dim strPath As String
> > Dim strPath1 As String
> > Dim strData As String
> >
> > strPath = "c:\Header.txt" 'Header Information file
> > strPath1 = "c:\Trans.Txt" 'Transactions file
> > strFirstQuery = "QryHeader"
> > strSecondQuery = "QryTransactions"
> >
> > 'Output Transaction Header
> > DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
> > 'OutPut Transactions
> > DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
> >
> >
> > Open strPath1 For Append Access Write As #1
> > Open strPath2 For Binary Access Read As #2
> >
> > Do
> > Line Input #2, strData
> > Write #1, strData
> > Loop Until EOF(2)
> >
> > Close #1
> > Close #2
> >
> > End sub
> >
> >
> > --
> > Wayne Morgan
> >
> >
> > "Michael" <Mikch_49@HotMail.Com> wrote in message
> > news:43e38787.0310100743.738fc1f8@posting.google.c om...[color=darkred]
> > > Wayne,
> > >
> > > Your first idea is exactly what I need to do, though I am unclear how
> > > to write the code to accomplish this. I have the two files outputting
> > > correctly, I just need to append the first (header.txt) to the second
> > > (trans.txt) Do you think you could provide an example?[/color][/color][/color] | | | | re: Appending Text file with a header record
I tried using the Do Until EOF but I get the same results. Funny
though I get my file correctly now or as soon as I reset after my
error I have a correctly formated file. But I still get a Run Time
Error Input past end of file on the last part of this routine. Anyone
have any ideas? I've added a second pass though to add a trailer file
to this and thats what's failing.
Thanks again to all!
Private Sub Command0_Click()
Dim strFirstQuery As String
Dim strSecondQuery As String
Dim strThirdQuery As String
Dim strPath As String
Dim strPath1 As String
Dim strPath2 As String
Dim strData As String
strPath = "c:\Header.txt" 'Header Information file
strPath1 = "c:\Trans.Txt" 'Transactions file
strPath2 = "c:\Trailer.Txt" 'Trailer file
strFirstQuery = "QryHeader"
strSecondQuery = "QryTransactions"
strThirdQuery = "QryTrailer"
'Output Transaction Header c:\Header.txt
DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
'OutPut Transactions c:\Trans.Txt
DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
'OutPut Transaction Trailer c:\Trailer.Txt
DoCmd.TransferText acExportFixed, "EE2", strThirdQuery, strPath2
Open strPath1 For Append Access Write As #2 ' Transactions
Open strPath2 For Binary Access Read As #3 ' Trailer
'Merge c:\Trans.Txt with C:\Trans.Txt This part works
Do
Line Input #3, strData
Print #2, strData
Loop Until EOF(2)
Close #2
Close #3
Open strPath1 For Binary Access Read As #1 ' Transactions
Open strPath For Append Access Write As #4 ' Header
'Merge C:\Trans.Txt with C:\Header.Txt
'This part fails with the Input past end of file error
Do Until EOF(1)
Line Input #1, strData '<< Error here
Print #4, strData
Loop 'While EOF(1) 'Until EOF(1)
Close #1
Close #4
End Sub
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++[color=blue]
>
> Do Until EOF(2)
> Line Input #2, strData
> Write #1, strData
> Loop
>
> Close #1
> Close #2
>
> You just need to test for EOF first, I think. Of course, you have to
> make sure then that you get the last record in textfile #1 into #2.[/color] | | | | re: Appending Text file with a header record
I tried using the Do Until EOF but I get the same results. Funny
though I get my file correctly now or as soon as I reset after my
error I have a correctly formated file. But I still get a Run Time
Error Input past end of file on the last part of this routine. Anyone
have any ideas? I've added a second pass though to add a trailer file
to this and thats what's failing.
Thanks again to all!
Private Sub Command0_Click()
Dim strFirstQuery As String
Dim strSecondQuery As String
Dim strThirdQuery As String
Dim strPath As String
Dim strPath1 As String
Dim strPath2 As String
Dim strData As String
strPath = "c:\Header.txt" 'Header Information file
strPath1 = "c:\Trans.Txt" 'Transactions file
strPath2 = "c:\Trailer.Txt" 'Trailer file
strFirstQuery = "QryHeader"
strSecondQuery = "QryTransactions"
strThirdQuery = "QryTrailer"
'Output Transaction Header c:\Header.txt
DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
'OutPut Transactions c:\Trans.Txt
DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
'OutPut Transaction Trailer c:\Trailer.Txt
DoCmd.TransferText acExportFixed, "EE2", strThirdQuery, strPath2
Open strPath1 For Append Access Write As #2 ' Transactions
Open strPath2 For Binary Access Read As #3 ' Trailer
'Merge c:\Trans.Txt with C:\Trans.Txt This part works
Do
Line Input #3, strData
Print #2, strData
Loop Until EOF(2)
Close #2
Close #3
Open strPath1 For Binary Access Read As #1 ' Transactions
Open strPath For Append Access Write As #4 ' Header
'Merge C:\Trans.Txt with C:\Header.Txt
'This part fails with the Input past end of file error
Do Until EOF(1)
Line Input #1, strData '<< Error here
Print #4, strData
Loop 'While EOF(1) 'Until EOF(1)
Close #1
Close #4
End Sub
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++[color=blue]
>
> Do Until EOF(2)
> Line Input #2, strData
> Write #1, strData
> Loop
>
> Close #1
> Close #2
>
> You just need to test for EOF first, I think. Of course, you have to
> make sure then that you get the last record in textfile #1 into #2.[/color] | | | | re: Appending Text file with a header record
"Michael" <Mikch_49@HotMail.Com> wrote in message
news:43e38787.0310140814.6b3a9bcb@posting.google.c om...[color=blue]
> I tried using the Do Until EOF but I get the same results.[/color]
Do While Not EOF(2) | | | | re: Appending Text file with a header record
----- Original Message -----
From: "Michael" <Mikch_49@HotMail.Com>
Newsgroups: comp.databases.ms-access
Sent: Tuesday, October 14, 2003 12:14 PM
Subject: Re: Appending Text file with a header record
<snip>
[color=blue]
> Open strPath1 For Append Access Write As #2 ' Transactions
> Open strPath2 For Binary Access Read As #3 ' Trailer
>
>
>
> 'Merge c:\Trans.Txt with C:\Trans.Txt This part works[/color]
<code change>
Input$ ( lof(3), strData)
Print #2, strData
</code change>
[color=blue]
> Close #2
> Close #3
>
> Open strPath1 For Binary Access Read As #1 ' Transactions
> Open strPath For Append Access Write As #4 ' Header
>
> 'Merge C:\Trans.Txt with C:\Header.Txt
> 'This part fails with the Input past end of file error[/color]
<code change>
Input$ (lof( 1) , strData)
Print #4, strData
</code change>
[color=blue]
> Close #1
> Close #4
>
>
> End Sub[/color] | | | | re: Appending Text file with a header record
When i try this ..
Input$ (lof( 1) , strData) << I get an Error here, "Compile Error Expected #"
Print #4, strData
Is this exactly how I should type this?
"rkc" <rkc@yabba.dabba.do.rochester.rr.com> wrote in message news:<rdcjb.58480$uA2.47409@twister.nyroc.rr.com>. ..[color=blue]
> ----- Original Message -----
> From: "Michael" <Mikch_49@HotMail.Com>
> Newsgroups: comp.databases.ms-access
> Sent: Tuesday, October 14, 2003 12:14 PM
> Subject: Re: Appending Text file with a header record
>
>
> <snip>
>[color=green]
> > Open strPath1 For Append Access Write As #2 ' Transactions
> > Open strPath2 For Binary Access Read As #3 ' Trailer
> >
> >
> >
> > 'Merge c:\Trans.Txt with C:\Trans.Txt This part works[/color]
>
>
> <code change>
> Input$ ( lof(3), strData)
> Print #2, strData
> </code change>
>[color=green]
> > Close #2
> > Close #3
> >
> > Open strPath1 For Binary Access Read As #1 ' Transactions
> > Open strPath For Append Access Write As #4 ' Header
> >
> > 'Merge C:\Trans.Txt with C:\Header.Txt
> > 'This part fails with the Input past end of file error[/color]
>
>
> <code change>
> Input$ (lof( 1) , strData)
> Print #4, strData
> </code change>
>[color=green]
> > Close #1
> > Close #4
> >
> >
> > End Sub[/color][/color] | | | | re: Appending Text file with a header record
----- Original Message -----
From: "Michael" <Mikch_49@HotMail.Com>
Newsgroups: comp.databases.ms-access
Sent: Tuesday, October 21, 2003 6:48 PM
Subject: Re: Appending Text file with a header record
[color=blue]
> When i try this ..
>
> Input$ (lof( 1) , strData) << I get an Error here, "Compile Error[/color]
Expected #"[color=blue]
> Print #4, strData
>
> Is this exactly how I should type this?[/color]
No. Don't know why I typed it like that.
strData = a variable of type string.
The following will cause the entire contents of the file opened as #1
to be loaded into strData.
strData = Input$(LOF(1), #1)
You should read up on the FreeFile function to assign a file handle.
Dim f1 as Long
f1 - FreeFile
Open "c:\Trans.Txt" For Binary As #f1 | | | | re: Appending Text file with a header record
If anyone is interested here is how I solved my problem ..
Private Sub Command9_Click()
Dim strFirstQuery, strSecondQuery, strThirdQuery As String
Dim strPath, strPath1, strPath2 As String
Dim strData, strResult As String
Dim strtmp, strfulltmp As String
strPath = "c:\Header.txt" 'Header
Information file
strPath1 = "c:\Trans.Txt"
'Transactions file
strPath2 = "c:\Trailer.Txt" 'Trailer
file
strResult = "C:\Result.Txt" 'Result of
the three merged files
strFirstQuery = "QryHeader"
strSecondQuery = "QryTransactions"
strThirdQuery = "QryTrailer"
'Output Transaction Header
DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
'OutPut Transactions
DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
'OutPut Transaction Trailer
DoCmd.TransferText acExportFixed, "EE2", strThirdQuery, strPath2
Open strPath For Input As #1 'Open Header
Open strPath1 For Input As #2 'Open Transactions File
Open strPath2 For Input As #3 'Open Trailer File
Open strResult For Output As #4 'Open Results File
Do While Not EOF(1)
Line Input #1, tmp
fulltmp = fulltmp & tmp & vbNewLine 'Read Header
Loop
Do While Not EOF(2)
Line Input #2, tmp
fulltmp = fulltmp & tmp & vbNewLine 'Read Transactions
Loop
Do While Not EOF(3)
Line Input #3, tmp
fulltmp = fulltmp & tmp & vbNewLine 'Read Trailer
Loop
Print #4, fulltmp 'Make Merged Results File
Close #4 'Close Files
Close #3
Close #2
Close #1
End Sub
Thanks for everyone's input! Mikch_49@HotMail.Com (Michael) wrote in message news:<43e38787.0310091233.3a99afd1@posting.google. com>...[color=blue]
> I have a data application in a2k that I need to create two fixed width
> text files and then combine them to a single file The first file is
> header information and the second is transaction data. I have tried
> and tried but just cant seem to get this right, I am using Queries to
> created my export files with specifications which works fine, I get
> stumped with the appending the header to my transaction file. What I
> have so far looks like this .. What I wind up in my file is,
>
> 1 2003100713250020441007
> "c:\Trans.Txt"
>
> What I need to know is how to declare the c:\trans.txt so it will
> append data and not the string
>
> Any help would be great!
>
> Thanks
>
> Michael
>
> +++++++++++++++++++++++++++++++++++++++++++++++++
>
> Private Sub Command0_Click()
>
> Dim strFirstQuery As String
> Dim strSecondQuery As String
> Dim strPath As String
> Dim strPath1 As String
>
>
>
>
>
> strPath = "c:\Header.txt" 'Header Information file
> strPath1 = "c:\Trans.Txt" 'Transactions file
> strFirstQuery = "QryHeader"
> strSecondQuery = "QryTransactions"
>
> 'Output Transaction Header
> DoCmd.TransferText acExportFixed, "EE2", strFirstQuery, strPath
> 'OutPut Transactions
> DoCmd.TransferText acExportFixed, "EE", strSecondQuery, strPath1
>
> Open strPath For Append As #1
> Write #1, strPath1
> Close #1
>
> End sub[/color] |  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|