Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / December 2003

Tip: Looking for answers? Try searching our database.

Saving data in several form fields to .txt file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Solsen - 16 Dec 2003 22:36 GMT
How can I save information in the fields of a from
document I sent to several people, into one .txt file?
Peter Jamieson - 17 Dec 2003 01:54 GMT
Do you have several different form documents, or are you filling in the
form, sending it, filling in different details, sending the form, etc.?

In any case, you're probably going to need a macro to do this as the
built-in method of saving form data cannot append data to an existing .txt

You could use something like the following (but you'd need to test it and
add error handling code):

Sub SaveFormData()
Const sDataFilePathName = "c:\a\mydata.txt"
Dim sOutputLine As String
Dim oFormField As FormField
Open sDataFilePathName For Append As #1
s = ""
For Each oFormField In ActiveDocument.FormFields
If s <> "" Then s = s & ","
Select Case oFormField.Type
' At the moment the processing its the same but you
' might want to change e.g. how you output the
' value of a checkbox
Case wdFieldFormTextInput
  s = s & """" & DoubleUp(CStr(oFormField.Result)) & """"
Case wdFieldFormDropDown
  s = s & """" & DoubleUp(CStr(oFormField.Result)) & """"
Case wdFieldFormCheckBox
  s = s & """" & DoubleUp(CStr(oFormField.Result)) & """"
Case Else
  s = s & """?"""
End Select
Next
Print #1, s
Close #1
End Sub

Function DoubleUp(ByRef s As String) As String
' doubles up any double quotes in the passed string
Dim i As Integer
DoubleUp = ""
For i = 1 To Len(s)
 If Mid(s, i, 1) = """" Then
   DoubleUp = DoubleUp & """"""
 Else
   DoubleUp = DoubleUp & Mid(s, i, 1)
 End If
Next
End Function

--
Peter Jamieson - Word MVP

> How can I save information in the fields of a from
> document I sent to several people, into one .txt file?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.