?
Solved

How can I save data from a form field?

Posted on 2003-02-22
4
Medium Priority
?
134 Views
Last Modified: 2010-05-01
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!
0
Comment
Question by:echobravo316
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Accepted Solution

by:
Hilapdatus earned 300 total points
ID: 8001552
Private Sub Command1_Click()
  Dim intFileNumber As Integer
  intFileNumber = FreeFile
 
  'Open the file specified in Text1 for output, if the
  'file does not exist it will be created
  Open Text1.Text For Output As #intFileNumber
 
  'Write text from Text2 to the output file
  Write #intFileNumber, Text2.Text
 
  'Close the file
  Close #intFileNumber
End Sub
0
 
LVL 18

Expert Comment

by:Sethi
ID: 8001625
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.
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8001700

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.







0
 
LVL 3

Author Comment

by:echobravo316
ID: 8001805
How can I get rid of the quotation marks in the output file?
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question