Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How can I save data from a form field?

Posted on 2003-02-22
4
Medium Priority
?
135 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
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

564 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