Write to a txt file when the forms loads

herbertioz

Registered User.
Local time
Today, 21:53
Joined
Nov 6, 2009
Messages
66
I want to write a line to a textfile every time the form loads.

Code:
Private Sub Form_Load()

Dim fs, textfile
Set fs = CreateObject("Scripting.FileSystemObject")
Set textfile = fs.CreateTextFile("c:\test\test.txt", True)
textfile.WriteLine ("The program started: " & Now() & vbCrLf)
End Sub

The problem is that it only writes the new line and not stores the old ones.

I have tried OpenTextFile but i am getting invalid argument.

Some suggestions from you guys?:)
 
I've found a solution:
I had to use OpenTextFile and ForAppending, not the number 3.(ref.http://msdn.microsoft.com/en-us/library/aa265347(v=vs.60).aspx)

Code:
Private Sub Form_Load()
Dim fs, textfile
Set fs = CreateObject("Scripting.FileSystemObject")
Set textfile = fs.OpenTextFile("c:\test\test.txt", ForAppending, TristateFalse)
textfile.WriteLine ("The program started: " & Now() & vbCrLf)
End Sub
 

Users who are viewing this thread

Back
Top Bottom