Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

add text to end of existing text in file

Posted on 2016-08-30
16
Medium Priority
?
85 Views
Last Modified: 2016-08-30
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.
0
Comment
Question by:QMBB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 11

Expert Comment

by:Craig Yellick
ID: 41777208
Any of the low-level file writing operations offer an "append" mode.

open strFileName For Append As #intFileNumber

Open in new window

0
 

Author Comment

by:QMBB
ID: 41777211
I got this working:

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

Open in new window


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.
0
 

Author Comment

by:QMBB
ID: 41777221
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).
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 11

Expert Comment

by:Craig Yellick
ID: 41777224
Try the PRINT statement instead of WRITE.
0
 

Author Comment

by:QMBB
ID: 41777230
:-) 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)?
0
 
LVL 11

Expert Comment

by:Craig Yellick
ID: 41777231
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.
0
 

Author Comment

by:QMBB
ID: 41777235
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).
0
 

Author Comment

by:QMBB
ID: 41777237
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
0
 
LVL 11

Expert Comment

by:Craig Yellick
ID: 41777249
0
 

Author Comment

by:QMBB
ID: 41777251
Yeah, I've seen lots of articles, was hoping for an example. Thanks anyway.
0
 
LVL 11

Accepted Solution

by:
Craig Yellick earned 2000 total points
ID: 41777259
That article is a complete example, reading data from one file and copying to another. It does exactly what you want to do, so I figured it was a waste of time to reformat into an E-E post.
0
 

Author Comment

by:QMBB
ID: 41777267
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.
0
 

Author Closing Comment

by:QMBB
ID: 41777273
That did it! Thanks much.
0
 
LVL 11

Expert Comment

by:Craig Yellick
ID: 41777278
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"

Open in new window

0
 

Author Comment

by:QMBB
ID: 41777279
That would work via batch file, correct?
0
 
LVL 11

Expert Comment

by:Craig Yellick
ID: 41777325
Sure would. No need for the SHELL command part since you'd already be out in the DOS shell environment.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question