Solved

Insert line at top of existing text file

Posted on 2008-06-23
4
632 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now