Solved

Insert line at top of existing text file

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

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…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

914 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

16 Experts available now in Live!

Get 1:1 Help Now