By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,473 Members | 1,274 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,473 IT Pros & Developers. It's quick & easy.

write to text file

P: n/a
The following code will "append" text to the END of the text file. How
can I add text to the beginning of a text file?

Dim fno As Integer

fno = FreeFile
Open "test.txt" For Append As #fno
Print #fno, "Hello World"
Close #fno

fno = FreeFile
Open "test.txt" For Append As #fno
Print #fno, "Hello World2"
Close #fno

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
rc*********@yahoo.com wrote:
The following code will "append" text to the END of the text file. How
can I add text to the beginning of a text file?


To the beginning and leave the rest of the file intact? I think you'd have to
create a new file write the new data and then copy the data from the old file.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 13 '05 #2

P: n/a
The text to be inserted at the beginning of the file is static text so
the "beggining" file (let's call it FileA) could already exist. If I
copy FileB to FileA will it insert all the text from FileB to the end
of FileA?

Nov 13 '05 #3

P: n/a

rc*********@yahoo.com wrote:
The text to be inserted at the beginning of the file is static text so the "beggining" file (let's call it FileA) could already exist. If I copy FileB to FileA will it insert all the text from FileB to the end
of FileA?


AFAIK, you can only insert at the end. So create a new text file, add
the header stuff, then copy the data from the old file. Save the new
file, delete the old one, and rename the new one. Just use the Name
function.

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.