Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Insert line at top of existing text file

Posted on 2008-06-23
4
Medium Priority
?
647 Views
Last Modified: 2009-07-29
Hi All,

I have a fixed width text file which I have created using a specification file and this is ok. Now I would like to append one(1) row of information at the top of the file which is also a fixed width only of a different length. Put simple its like having two recordsets with different fixed width length being appended to the same file.

Regards
0
Comment
Question by:tristan69
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:jefftwilley
ID: 21845908
You can modify this bit I think. It basically opens a new output file, and reads in your old one after adding the first line.

Function AddHeader(FileIn As String, FileOut As String)
Dim strTAG As String
Dim strIn As String
strTAG = "ABCXYZ"
Open FileOut For Output As #2
    Print #2, strTAG
Open FileIn For Input As #1
    Do Until EOF(1)
        Line Input #1, strIn
        Print #2, strIn
    Loop
Close #1
Close #2
End Function
0
 

Author Comment

by:tristan69
ID: 21846315
I tried this and it work, and i guess i can use this as the solution. Even though I was thinking of something more along the lines of get the first recordset write it to the text file using some kind of specification, then take the other and write it to the same file using a different specification.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 21847984
Have you tried the way your're describing? I believe the output method is destructive..meaning it overwrites the old file. You can test it as you wish. Another option would be to write your recordsets to a temp table then output the final contents to a text file.
J
0
 

Accepted Solution

by:
tristan69 earned 0 total points
ID: 21926186
Hi Guys,
Here is what the solution look like I am posting it here just in case someone wants to see.

Public Function JoinNISFiles(Header As Variant)
Dim oFS As FileSystemObject
Dim oFS1 As FileSystemObject

Dim oTS As TextStream
Dim oTS1 As TextStream

Dim vTemp

Set oFS = New FileSystemObject
Set oFS1 = New FileSystemObject
sBackupPath = CurrentProject.path & "\" & "GMP NISUPLOADS\"

Set oTS = oFS.OpenTextFile(sBackupPath & "NISFileUpload.txt", ForReading)
vTemp = oTS.ReadAll

Set oTS1 = oFS.OpenTextFile(sBackupPath & Header & ".txt", ForAppending, True)
oTS1.Write (vTemp)

End Function

Thanks to evereone who responded.

Tristan69

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

916 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