Bobby
asked on
add text to end of existing text in file
I have a text file with a bit of text at top and then a bunch of tab spaces after that text. Is it possible to append a bunch of text after all the tab spaces, so that the top text and tab spaces in the beginning of the file remains intact? The data that I need to append will come from an Access 2003 table, so I could use VB6 if need be.
ASKER
I got this working:
But it adds the " around the text, can't have that. Also, I need to call data from a table, have it export and write (append) to this file as tab delim.
Private Sub Command180_Click()
Dim strFile_Path As String
strFile_Path = "C:\temp\test.txt"
Open strFile_Path For Append As #1
Write #1, "my text to append"
Close #1
End Sub
But it adds the " around the text, can't have that. Also, I need to call data from a table, have it export and write (append) to this file as tab delim.
ASKER
Figured out the quotes... used Print instead of Write, and it doesn't output the quotes.
Only thing left is to get the data... I figure I can set up an auto-export job using a saved export spec once an hour to a different txt file, overwriting every time. Then, after that file has been created, I run this code to append the contents to the other text file (like my question started with). But I dont know how to call that second text file as the source of data to be appended... I need to replace "my text to append" with a path to the file (maybe).
Only thing left is to get the data... I figure I can set up an auto-export job using a saved export spec once an hour to a different txt file, overwriting every time. Then, after that file has been created, I run this code to append the contents to the other text file (like my question started with). But I dont know how to call that second text file as the source of data to be appended... I need to replace "my text to append" with a path to the file (maybe).
Try the PRINT statement instead of WRITE.
ASKER
:-) got that. Now how do I grab the contents of a text file as the data to be appended, rather than have the data in the code (as in the snippet above)?
In that case you'd need to open the source file as another file handle, and read from it then write to the output file. How complex is the record source? I'd probably go with outputting the query result directly to the output file.
ASKER
It is about 70 fields, tab delimited. Id like to preserve the tab delimited txt file export from Access, because I know that works in the upload Im doing (Amazon inventory).
ASKER
Isnt there just a simple way to replace this:
Write #1, "my text to append"
with something like this:
Write #1, C:\DataTo Be Appended.txt
Write #1, "my text to append"
with something like this:
Write #1, C:\DataTo Be Appended.txt
ASKER
Yeah, I've seen lots of articles, was hoping for an example. Thanks anyway.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Using the MS example you posted, I'll have to start all over again but I'm already 95% there. Maybe it's worth it... I'll try it.
ASKER
That did it! Thanks much.
Did you see the second method that uses DOS COPY? Pretty slick, one line of code.
Shell "command.com /c" & _
"copy c:\dest.txt+c:\source.txt c:\dest.txt /b"
ASKER
That would work via batch file, correct?
Sure would. No need for the SHELL command part since you'd already be out in the DOS shell environment.
Open in new window