ÿþ characters in txt file

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,
 
J

Jack Leach

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.

Why go through all this? Why not just arrange the data in a temp table
(exporting text like this only needs two fields... line number and line
content).

You seem to be organizing data via text file transfer and renaming, rather
than in the application that is made to do it.

I can't think of any reason why this couldn't be arranged in access into a
format that can be directly outputted to a single text file. If you want
another file for whatever other reasons with related data, build it in a temp
table and output it. Same if you want to combine two files... I would pull
both into temps, do your logic in vba, and export a single file back out.

As testimonial, my first project using the vba i/o functions like this was
to convert and post a single-line based manufacturing NC programs for cutting
metals and plastics. There's e few different types of machines, and each
takes a slightly different language. So I have one master for each part kept
in a text file. I import this into a few temps, run all sorts of functions
on one of them to create the other versions of the language, add a header and
footer to each one with job info, etc, and export the files to disk only
after they are complete from this internal process. It works like a charm.

I would give it a shot.

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)



RJF said:
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,
 
R

RJF

Hi Jack,

Thanks for your quick response on this. I understand what you're saying. I
started what you suggested then my boss changed my priorities (again). I'm
anxious to get back to it and I will post again when I do.

Thanks again.

--
RJF


Jack Leach said:
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.

Why go through all this? Why not just arrange the data in a temp table
(exporting text like this only needs two fields... line number and line
content).

You seem to be organizing data via text file transfer and renaming, rather
than in the application that is made to do it.

I can't think of any reason why this couldn't be arranged in access into a
format that can be directly outputted to a single text file. If you want
another file for whatever other reasons with related data, build it in a temp
table and output it. Same if you want to combine two files... I would pull
both into temps, do your logic in vba, and export a single file back out.

As testimonial, my first project using the vba i/o functions like this was
to convert and post a single-line based manufacturing NC programs for cutting
metals and plastics. There's e few different types of machines, and each
takes a slightly different language. So I have one master for each part kept
in a text file. I import this into a few temps, run all sorts of functions
on one of them to create the other versions of the language, add a header and
footer to each one with job info, etc, and export the files to disk only
after they are complete from this internal process. It works like a charm.

I would give it a shot.

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)



RJF said:
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,
 
R

RJF

Hi Jack,

I finally was able to get back to work on this. I tried your suggestion and
it's working. Thanks for your help. Guess I was making things a lot harder
than they had to be.

Thanks again.

--
RJF


Jack Leach said:
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.

Why go through all this? Why not just arrange the data in a temp table
(exporting text like this only needs two fields... line number and line
content).

You seem to be organizing data via text file transfer and renaming, rather
than in the application that is made to do it.

I can't think of any reason why this couldn't be arranged in access into a
format that can be directly outputted to a single text file. If you want
another file for whatever other reasons with related data, build it in a temp
table and output it. Same if you want to combine two files... I would pull
both into temps, do your logic in vba, and export a single file back out.

As testimonial, my first project using the vba i/o functions like this was
to convert and post a single-line based manufacturing NC programs for cutting
metals and plastics. There's e few different types of machines, and each
takes a slightly different language. So I have one master for each part kept
in a text file. I import this into a few temps, run all sorts of functions
on one of them to create the other versions of the language, add a header and
footer to each one with job info, etc, and export the files to disk only
after they are complete from this internal process. It works like a charm.

I would give it a shot.

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)



RJF said:
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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top