Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a text file

Status
Not open for further replies.

JonathonC

Technical User
Aug 18, 2001
43
GB
I have 2 text boxs and a command button on a form, when the button is clicked I want "whatever_has_been_typeded_in_the_first_text_box.txt" to be created. Also the contents of the second text box I want to be put into the text file. I then want the file to be saved to the directory, C:\text
Thanks,

Jonathon.
 
Open "C:\text\" & Textbox1 & ".txt" for output as #1
Print #1, Textbox2
Close
DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
Hi,

..but if the path doesn't exist you have to do it like that,
otherwise a runtime-error will occur :

Dim dateiname As String, dateinr As Integer
DirPath = "C:\text\"
dateiname = DirPath & textbox1.Text & ".txt"
'Check if path exists and create
If Dir$(DirPath & "\.") = "" Then
MkDir (DirPath)
End If
'go on writing the file
dateinr = FreeFile
Open dateiname For Output As dateinr
Print #dateinr, textbox2.Text
Close dateinr
'eyerything done
MsgBox "File saved to " & dateiname
End Sub


bateman23
...visit me @:
 
Thanks you two, in the end I used Bateman23's code.

Jonathon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top