Do you know how to create a textfile based on the textbox's contents?

  • Thread starter Mitchell_Collen via AccessMonster.com
  • Start date
M

Mitchell_Collen via AccessMonster.com

Hi
(I posted in general2 on accident)
I have a textbox that will contain one to many values all of which are comma
delimited. Do you know how to create a textfile based on the textbox's
contents? This would be ran on a click event.

Thanks
MC
 
A

Allen Browne

If the text box is bound to a table, you could use TransferText to export
the data from the table to a text file (e.g. comma separated values.)

If the text box is unbound, you could write VBA code to create the text
file. You will need some experience with code to achieve this. It starts
like this:
iFile = FreeFile
strDoc = "C:\SomeFolder\SomeFile.txt"
Open strDoc For Output AS #iFile
 
M

Mr. B

Mitchell,

YOu will need to change a couple of things, but try the following code in
the OnClick event of your button:

'start of code
Dim strVal As String
Dim varCharLoc As Integer
Dim varStart As Integer
Dim strContent As String
Dim varStartChar As Integer
'change the "NameOfYourTextBox" to the actual name of your textbox
strContent = Me.NameOfYourTextBox
'here specify the path and the filename you want to use
Open "C:\__Temp\myfile.txt" For Output As #1

varStart = 1
varStartChar = 1
CheckForComma:
varCharLoc = InStr(varStart, strContent, ",")
If varCharLoc > 0 Then
strVal = Mid(strContent, varStartChar, varCharLoc - varStartChar)
Print #1, strVal
varStartChar = varCharLoc + 3
varStart = varCharLoc + 1
'check for the next comma
GoTo CheckForComma
Else
'write the last value
strVal = Right(strContent, Len(strContent) - varStart)
Print #1, strVal
End If
Close #1

'end of code

HTH
Mr. B
(ackdoctoraccess dot com)
 
M

Mitchell_Collen via AccessMonster.com

Thanks Mr. B! Your help was straight forward and the code worked perfect!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top