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 / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Linking fields in Word forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 26 Oct 2006 04:04 GMT
I have about 12 forms (separate Word files) which have common fields (e.g.
project number).  Is there a way to populate all forms with the common data
when the first form is filled in?

Thanks
Mike
Peter Jamieson - 26 Oct 2006 16:56 GMT
It should, broadly speaking, be possible. Some rather poor code to get you
started - imagine you have c:\test\Doc1.doc open, have filled in a form,
then click a button connected to the CopyFormDataToAllDocs sub which should
copy values to doc2.doc and doc3.doc and leave them open.

You might of course need to consider any number of additional things, e.g.
a. error handling in general
b. dealing with different types of form field (this will cope with text
fields)
c. dealing with fields in different documents with the same names but
different types, or different lengths etc. etc.

Peter Jamieson

Sub CopyFormDataToAllDocs()
 Call CopyFormDataToOneDoc(ActiveDocument, "c:\test\doc2.doc")
 Call CopyFormDataToOneDoc(ActiveDocument, "c:\test\doc3.doc")
End Sub

Sub CopyFormDataToOneDoc(objSourceDocument As Word.Document, pathname As
String)
Dim objTargetDocument As Word.Document
Dim objSourceField As Word.FormField
Dim objTargetField As Word.FormField
Set objTargetDocument = Application.Documents.Open(pathname)
For Each objSourceField In objSourceDocument.FormFields
 On Error GoTo NoSuchField
 Set objTargetField = objTargetDocument.FormFields(objSourceField.Name)
 MsgBox objSourceField.Name & ": " & objSourceField.Result
 objTargetField.Result = objSourceField.Result
 Set objTargetField = Nothing
NoSuchField:
 Err.Clear
 On Error GoTo 0
Next
Set objTargetDocument = Nothing
End Sub
>I have about 12 forms (separate Word files) which have common fields (e.g.
> project number).  Is there a way to populate all forms with the common
[quoted text clipped - 3 lines]
> Thanks
> Mike

Rate this thread:






 
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.