aziz rasul
06-15-2007, 05:43 AM
I have 3 text files. Call them File1.txt, File2.txt and File3.txt. Each of them are in UTF-8 format.
By using the Open statement, I want to open File2.txt and File3.txt and append all the records into File1.txt.
How do I do this?
Moniker
06-17-2007, 10:20 AM
You're not going to do that with an Open statement. If you aren't comfortable with coding it, import all the FileX.txt files as tables, append File2.txt to File3.txt, and then append File3.txt to File1.txt. Finally, export File1.txt. You can do this with simple queries and a minimum amount of programming (if you want to automate the import/export). You could even do it with queries and a macro.
aziz rasul
06-18-2007, 12:00 AM
Unfortunately, each of the 3 pieces of data have different number of fields which means that I end up having trailing ';' which the spec of the final file does not allow, hence using the Open statement.
If the DoCmd.TransferText allowed APPENDING of data to existing text files, that would have resolved the problem easily.
chergh
06-18-2007, 12:41 AM
Try this:
sub AppendFiles()
call AppendFiles1("file2.txt")
call AppendFiles1("file3.txt")
end sub
Sub AppendFiles1(file_name as string)
Dim SourceNum As Integer
Dim DestNum As Integer
Dim Temp As String
On Error GoTo ErrHandler
DestNum = FreeFile()
Open "file1.txt" For Append As DestNum
SourceNum = FreeFile()
Open file_name For Input As SourceNum
Do While Not EOF(SourceNum)
Line Input #SourceNum, Temp
Print #DestNum, Temp
Loop
CloseFiles:
Close #DestNum
Close #SourceNum
Exit Sub
ErrHandler:
MsgBox "Error # " & Err & ": " & Error(Err)
Resume CloseFiles
End Sub
aziz rasul
06-18-2007, 05:10 AM
OK. That worked. Many thanks.
One other issue is that I have a extra blank line at the end of the file. Is there a way of opening the file after it's done the above and removing the blank line by code. The resultant file is used on the web and it doesn't like this last empty line which I presume is a carriage break.