Re: write input values from users to a text file



Do you really want to write just that one brief line of text? If so, you
can do it with something like this, using the WriteToFile() procedure at
the end of this message.

Dim strS As String

strS = InputBox("enter the node nos of elemnts end points:")
WriteToFile strS, "C:\Folder\File.txt", True


On Thu, 31 Mar 2005 15:07:59 GMT, "Nagendra Singh Dhakar via
AccessMonster.com" <forum@xxxxxxxxxxxxxxxxx> wrote:

>i want to write a vba code which will do the following process..
>
>1. prompt user for input like..." enter the node nos of elemnts end points
>:"
>2. user enter some valuse like.... 2,4
>3. write this input to a text file like.... E, 1, 2, 4
> where E for element and 1 for no of element
>
>plzzz help me..
>
>nsdhakar


Function WriteToFile(Var As Variant, _
FileSpec As String, _
Optional Overwrite As Long = True) _
As Long
'Writes Var to a textfile as a string.
'Returns 0 if successful, an errorcode if not.

'Overwrite argument controls what happens
'if the target file already exists:
' -1 or True (default): overwrite it.
' 0 or False: append to it
' Any other value: abort.

Dim lngFN As Long

On Error GoTo Err_WriteToFile
lngFN = FreeFile()
'Change Output in next line to Append to
'append to existing file instead of overwriting
Select Case Overwrite
Case True
Open FileSpec For Output As #lngFN
Case False
Open FileSpec For Append As #lngFN
Case Else
If Len(Dir(FileSpec)) > 0 Then
Err.Raise 58 'File already exists
Else
Open FileSpec For Output As #lngFN
End If
End Select
Print #lngFN, CStr(Nz(Var, ""));
Close #lngFN
WriteToFile = 0
Exit Function
Err_WriteToFile:
WriteToFile = Err.Number
End Function
--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.



Relevant Pages