Results 1 to 2 of 2

Thread: Overwrite a text file when command button is clicked..

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    9

    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

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    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.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


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
  •  



Click Here to Expand Forum to Full Width