|
-
Jul 3rd, 2012, 08:11 AM
#1
Thread Starter
New Member
Overwrite a text file when command button is clicked..
Hi all, I have a piece of code that writes fields to a text file when the command button is clicked by the user. The problem is, every time the user clicks the command button it writes the fields to the text file again..and again..and again..
What I would like it to do, is when the user clicks the command button, it writes once, and if it is clicked again, it overwrites what is previously written...
Code:
Private Sub Command1_Click()
Dim path As String
path = "C:\test.INI" ' Where the file is written to.
Dim ss As String
ss = FreeFile
If FExist(path) Then
Open path For Append As #ss
Else
Open path For Output As #ss
End If
Print #ss, Name.Text ' Fields written
Print #ss, PhoneNumber.Text
Print #ss, Address.Text
Close #ss
End Sub
-
Jul 3rd, 2012, 08:17 AM
#2
Re: Overwrite a text file when command button is clicked..
then dont use For Append As, use only For Output As, eventhough file not exists it wil create, but not folder.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|