R
RJF
Using Access 2000, I'm exporting a query to a text file (.txt).
strSaveFileName is my path and name of the txt file. I need to add a Header
to this txt file. Nothing specific so I'm just using the word "Header".
When I first did this, I was in a big hurry so I just created a table in my
database that was formatted the same way as the query I was outputting and
used a UNION query combining them. Then I exported each UNION query to a
text file. I had multiple Header tables in Access because there are
different formats for each query to be exported.
Now I'm cleaning it up and hope to get rid of the Header tables and UNION
queries and just add the select query to the txt file after the export.
So, first I export the select query to strSaveFileName.
Then I create a Header text file.
I'm not having a problem exporting each file. But when I try to append one
file to the other, I get the characters ÿþ in the beginning of the file,
right after the Header line.
I'm exporting the Header file. Header file exports fine. (Header.txt) It
contains no ÿþ characters.
I'm exporting the data file. Data file exports fine. (strSaveFileName) It
contains no ÿþ characters.
I then append the strSaveFileName text file to the Header.txt file.
I kill the strSaveFileName file.
I rename the Header file to the strSaveFileName file name.
I kill the Header.txt file.
Now the new strSaveFileName file contains the ÿþ characters.
Here's the code i'm using to append the data:
Dim SourceNum As Integer
Dim DestNum As Integer
Dim Temp As String
Open [Forms]![frm_ClientConv]!txt_FilePath & "HEADER.txt" For Output
As #1
Print #1, "HEADER"
Close #1
' Open the destination text file.
DestNum = FreeFile()
Open [Forms]![frm_ClientConv]!txt_FilePath & "HEADER.txt" For Append
As DestNum
' Open the source text file.
SourceNum = FreeFile()
Open strSaveFileName For Input As SourceNum
' Include the following line if the first line of the source
' file is a header row that you do not want to append to the
' destination file:
' Line Input #SourceNum, Temp
' Read each line of the source file and append it to the
' destination file.
‘IT’S AT THIS POINT WHERE THE ÿþ CHARACTERS ARE BEING
‘ADDED TO THE FILE.
Do While Not EOF(SourceNum)
Line Input #SourceNum, Temp
Print #DestNum, Temp
Loop
CloseFiles:
' Close the destination file and the source file.
Close #DestNum
Close #SourceNum
strRenamed = strSaveFileName
Kill strSaveFileName
SourceFile = [Forms]![frm_ClientConv]!txt_FilePath & "HEADER.txt"
' Define source file name.
DestinationFile = strRenamed
' Define target file name.
FileCopy SourceFile, DestinationFile
' Copy source to target.
Kill SourceFile
If I haven’t explained myself clearly or you need more information, please
let me know. I’m sure I’m missing something really easy.
Thank you in advance for any help you may be able to give.
Thanks,
strSaveFileName is my path and name of the txt file. I need to add a Header
to this txt file. Nothing specific so I'm just using the word "Header".
When I first did this, I was in a big hurry so I just created a table in my
database that was formatted the same way as the query I was outputting and
used a UNION query combining them. Then I exported each UNION query to a
text file. I had multiple Header tables in Access because there are
different formats for each query to be exported.
Now I'm cleaning it up and hope to get rid of the Header tables and UNION
queries and just add the select query to the txt file after the export.
So, first I export the select query to strSaveFileName.
Then I create a Header text file.
I'm not having a problem exporting each file. But when I try to append one
file to the other, I get the characters ÿþ in the beginning of the file,
right after the Header line.
I'm exporting the Header file. Header file exports fine. (Header.txt) It
contains no ÿþ characters.
I'm exporting the data file. Data file exports fine. (strSaveFileName) It
contains no ÿþ characters.
I then append the strSaveFileName text file to the Header.txt file.
I kill the strSaveFileName file.
I rename the Header file to the strSaveFileName file name.
I kill the Header.txt file.
Now the new strSaveFileName file contains the ÿþ characters.
Here's the code i'm using to append the data:
Dim SourceNum As Integer
Dim DestNum As Integer
Dim Temp As String
Open [Forms]![frm_ClientConv]!txt_FilePath & "HEADER.txt" For Output
As #1
Print #1, "HEADER"
Close #1
' Open the destination text file.
DestNum = FreeFile()
Open [Forms]![frm_ClientConv]!txt_FilePath & "HEADER.txt" For Append
As DestNum
' Open the source text file.
SourceNum = FreeFile()
Open strSaveFileName For Input As SourceNum
' Include the following line if the first line of the source
' file is a header row that you do not want to append to the
' destination file:
' Line Input #SourceNum, Temp
' Read each line of the source file and append it to the
' destination file.
‘IT’S AT THIS POINT WHERE THE ÿþ CHARACTERS ARE BEING
‘ADDED TO THE FILE.
Do While Not EOF(SourceNum)
Line Input #SourceNum, Temp
Print #DestNum, Temp
Loop
CloseFiles:
' Close the destination file and the source file.
Close #DestNum
Close #SourceNum
strRenamed = strSaveFileName
Kill strSaveFileName
SourceFile = [Forms]![frm_ClientConv]!txt_FilePath & "HEADER.txt"
' Define source file name.
DestinationFile = strRenamed
' Define target file name.
FileCopy SourceFile, DestinationFile
' Copy source to target.
Kill SourceFile
If I haven’t explained myself clearly or you need more information, please
let me know. I’m sure I’m missing something really easy.
Thank you in advance for any help you may be able to give.
Thanks,