Link to home
Start Free TrialLog in
Avatar of echobravo316
echobravo316Flag for United States of America

asked on

How can I save data from a form field?

After I create a basic form lets call it Form1 and it has 2 textbox fields with 1 command button.  How can I program the command button to save the text from the two boxes in a text file? I want the form to create a different file for each time the command button is pressed using textbox 1 as the filename.  Please explain the steps required.  Thnks!
ASKER CERTIFIED SOLUTION
Avatar of Hilapdatus
Hilapdatus

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Set References to Microsoft Scripting Runtime in your VB project.

Declare the following variables in Declaration section:
     Public objFSO As FileSystemObject
Public objTextFile As TextStream

Create the following Sub to Write to a textfile:
Public Sub WriteToFile()
     strFileName="C:\My Documents\Testing.txt"
         Set objTextFile = objFSO.OpenTextFile(strFileName, ForWriting)
End Sub
'--- strFileName is the file name where you want to write the text along with the full path of the file.
Avatar of Jacamar
Jacamar


Dim inFileNumber As Integer

Private Sub Command1_Click()
Dim Filename As String

inFileNumber = inFileNumber + 1

Filename = App.Path + "/FileMade.txt" & inFileNumber

Open Filename For Output As #1

Print #1, Text1.Text
Print #1, Text2.Text

Close #1

End Sub


This works.....i've tried it.  Make sure the  inFileNumber Statement is in the general declarations.

Jacamar.







Avatar of echobravo316

ASKER

How can I get rid of the quotation marks in the output file?