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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word "Automation" (for lack of a better term) 2

Status
Not open for further replies.

Scott24x7

Programmer
Jul 12, 2001
2,828
JP
All,
I'm looking for some "conceptual level" help on how to accomplish the following in word.
I have a Word document that I need to capture a number of data elements on. (Like Company Name, Contact, Address, Telephone, Fax, etc.). This form is the basis for a set of other "Forms". I then want to put a "Magic Button" in the document, that when I press it, populates other Word Templates with the corresponding Data Fields.
Can anyone point me in the right direction on what elements I need to do this with? I get "Form Fields", but I don't understand how to make them "work" across documents, especially how I can "open" the other document and populate it automatically.
The idea here is, it will save a lot of time, and cut down on mistakes made in data entry when populating the other forms with the same information.
Appreciate the help.


Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
You can also possibly get something from the FAQ on formfields here.

Basically, the conceptual structure could be something like:
Code:
 Sub MagicButton()
Dim ThisDoc As Document
Dim ThatDoc As Document
Dim file
Dim path As String
Dim ThisDocFF As FormFields
Dim ThatDocFF As FormFields
Dim oFF As FormField
Dim j As Long
j = 1

Set ThisDoc = ActiveDocument
Set ThisDocFF = ThisDoc.FormFields

path = "C:\Yadda\"
file = Dir(path & "*.doc")
Do While file <> ""
   ThatDoc = Documents.Open Filename:= path & file
   Set ThatDocFF = ThatDoc.FormFields
   For Each oFF In ThisDocFF
      ThatDocFF(j).Result = oFF.Result
      j = j + 1
   Next
   With ThatDoc
      .Save
      .Close
   End With
   j = 1
   file = Dir
Loop
End Sub

This may not be what you need, as you use the words "populates other Word Templates ". Are these really template files....or document files. Hopefully the latter. In any case, what the code above does:

1. declare a bunch of variables
2. sets a Document object for current document
3. sets a Formfield objects for ALL the formfields in the current document
4. sets a Dir function for all .doc files in the C:\Yadda folder
5. using Dir, opens each .doc file in that folder
6. makes the new document formfields results EQUAL the results in the current (source) document formfields
7. save, close the new file
8. continue on to the next file in the folder and repeats

faq219-2884

Gerry
My paintings and sculpture
 
Hi Gerry,

If I were to go down that path, I'd be inclined to use INCLUDETEXT fields in each child document linking back to the parent document. That way, there's no need to ensure all the formfields exist in the child documents - and in the same order - as your code assumes. With this approach, there's no need to open the chold documents until the user is ready to do something with them.

The concern I have with Scott's outline is that, if two or more updates are made to the parent documents before the child documents are used, only the last parent document's updates will still exist when the child documents are opened. By combining all the forms in the one file, that can be prevented by saving the updated file with a new name, or at least printing the set before moving on to the next round of data.

Cheers

[MS MVP - Word]
 
Oh heck, I was just tossing that out. I do not have a good idea what is the actual real situation. The OP did not even mention the idea of multiple existing files, which my code played around with.

From the OP:

"populates other Word Templates with the corresponding Data Fields."

My bolding.

Templates. Uh, really? Ummm. But yes, it could very well be the best/easiest route would be INCLUDETEXT fields.

Don't really know unless the specs/requirements are spelled out in more detail.

faq219-2884

Gerry
My paintings and sculpture
 
Hi guys,
Thanks for the hints so far... I'm now exploring the INCLUDETEXT fields, which I've not worked with before, as my original "thought" seems to be the wrong approach. :)
This was handed to me by someone recently who was trying to solve a problem,and I'm kind of known as "The guy who figures stuff out..." I don't have extensive VBA or Word background in this area. So to try to clarify a little:
There is a form, that has some "fields" on it, like:
Company Name
Project Name
Account Manager
Date of Project
etc.

With, "Fields" to be populated next to them.
Then there are some "Magic Buttons" on the bottom of the document, which say things like:
Change Request
Which then launches a "Change Request Form" by having a hyperlink on the button that referneces the template for CR's. They wanted to figure out a way to populat the "Common" information for these documents (as we create them all the time) from the "Project Information" document.
I had originally thought maybe there was some way to create Form Fields, with the same name in both docs, and upon launch from the hyperlink some how populate that data (yeah, I get it... big assumption on the HOW). So, if that's any clearer, I still haven't really solved this problem yet.


Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Hi Scott,

INCLUDETEXT fields will work fine for this. All you'd need to have happen is for your Change Request Form to use INCLUDETEXT fields pointing to the formfield bookmark names:
Company Name
Project Name
Account Manager
Date of Project
etc. in your Project Information document. Then, all your CR button has to do is to fire off a macro to open up the Change Request Form and run '.Fields.Update' - and not even that much if Word is set up to update links on opening files. The CR button's macro could even be coded to save the Change Request Form with a meaningful name.

Cheers

[MS MVP - Word]
 
Macropod,
Thanks for that. I will give the INCLUDETEXT fields a play, and see if I can create what you are suggesting here.


Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Hi Scott,

Since I imagine the Change Request Form will be opened in the same folder as the Project Information document, you might want to code the INCLUDETEXT fields so that they incorporate relative paths. Doing this is far from intuitive. To see how, check out the solution I've
posted at:

Oh, and since the INCLUDETEXT fields will be pointing to a protected source document, you'll need to add the \! switch to the end (see Word's Help file).

Cheers

[MS MVP - Word]
 
Thanks to you both very much for your help with this. It's not a trivial matter to make this work, I am finding! I'm sure I'll get it all running in a couple days.
Cheers!


Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top