Results 1 to 2 of 2

Thread: [RESOLVED] Write Textboxes to comma separated Text file

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    10

    Resolved [RESOLVED] Write Textboxes to comma separated Text file

    Hello,

    I just started programming in VBA please bear with me if this question is too basic.
    I’ve got a bunch of textboxes and I want to read the values of these boxes into a comma separated text file. So far I’ve got this
    Code:
    Private Sub CommandButton1_Click()
    dDate = DateSerial(Year(Date), Month(Date), Day(Date))
    
     'Open browse window om bestand te selecteren
    NewFN = Application.GetSaveAsFilename("C:\Documents and Settings\Test", "Text File (*.txt), *.txt")
    
    sFile = NewFN
    
    If NewFN = False Then
        Exit Sub
    Else
        Dim cCont As Control
        Dim vaFields As Variant
    
        'set and open file for output
        FNum = FreeFile()
        Open NewFN For Append As FNum
                
        Print #FNum, dDate; ","; TextBox1.Text
        Close #FNum
        
    End If
    
    End Sub
    This works fine but this is with only one textbox I’ve got a lot more and therefore I would like to have some kind of loop which loops trough all the textboxes and writes the values to the comma separated text file. Is this possible? And if so how?

    Barry

  2. #2
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    Re: Write Textboxes to comma separated Text file

    I don't know if i fully understand what your trying to do, but if your trying to place the data of all your text boxes into a single .txt file that separates the data of each of your text boxes with a comma then this is how you can do it:



    Code:
    Dim Box1 As String
    Box1 = TextBox1.Text
    
    Dim Box2 As String
    Box2 = TextBox2.Text
    
    
    Dim YourData As String = "Your text here" & Box1 & "Your Text Here" & Box2 & "Your Text Here"
    TextBox3.Text = YourData


    Now you can replace the "Your Text Here" with a comma like this "," .
    You can add as many text boxes as you need.
    And now you have one textbox with all your information.
    Last edited by helio2; Mar 26th, 2007 at 11:25 AM.

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