Solved

Insert line at top of existing text file

Posted on 2008-06-23
4
635 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

825 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