Form fields versus mail merge fields

  • Thread starter Thread starter maxmcclo
  • Start date Start date
M

maxmcclo

Hi,
I have an application which needs to communicate with MS Word to
generate documents.
Typically my application will want to generate 1 document at a time.
The user will select a template name and then choose to build a
document.
My application then has the responsibility of populating the document
with values.
I have created document templates in MS Word which contain form fields.
I have given my fields bookmark names.
I am using COM automation to communicate with Word and I am using
WordBasic interface to call the functions I need performed.
I can start Word and give it a template to open. I then ask it for all
the bookmark names.
I then cycle through each bookmark and populate it via doing a 'GoTo'
bookmark followed by an 'Insert'. It all seems to be working.
Questions
1) what about using mail merge fields. Can I achieve the same thing
using a mail merge ? Is it any easier ? Do I need to build a data
source file containing all my data and then do a mail merge ?
2) the WordBasic interface is now old technology. What is a more modern
approach to achieving my requirements ?
3) In general what is the best approach to having my application
generate Word documents for my users ?

Thanks
 
Mailmerge would almost certainly be easier. Formfields are not meant to be
used the way you are using them. You could use regular bookmarks as easily
without the formfields.

I regularly produce mailmerges with just one record being used. You would
build a data source, which can hold multiple records. So long as you build
it with each record having a unique identifier, you should be able to
automate inserting a particular record fairly easily. (Says one who has not
done this!)

http://word.mvps.org/FAQs/MailMerge/CreateAMailMerge.htm
http://word.mvps.org/FAQs/MailMerge/CreateADataSource.htm

Much more at http://word.mvps.org/FAQs/Mailmerge.htm and
http://addbalance.com/word/wordwebresources.htm#mailmerge
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Hi (e-mail address removed),

Generally, I'd use bookmarks (Insert/Bookmark) rather than form fields if
the user isn't expected to type into the form fields.

Instead of WordBasic, these days VBA is used. And I recommend it as
WordBasic is slowly beginning to come apart at the seams when the
technology behind the Word application has changed radially enough.

To write data into a particular Word bookmark:
Dim doc as Word.Document
Dim rng as Word.Range

Set doc = documents.Add(Template:="Path to *.dot file")
If doc.Bookmarks.Exists("Name") Then
Set rng = doc.Bookmarks("Name").Range
rng.Text = "My data"
End If

Note: if required, the bookmark can be recreated after inserting the data
doc.Bookmarks.Add Range:=rng, Name:="Name"

Using GoTo to jump to bookmarks is no longer necessary. NOT doing so will
be faster.

Personally, I would NOT try to use mail merge for this. The reasons:
- you'd need to build the data source from your data, save that to file
- then make sure the mail merge document links up to it, and because
in modern versions of Word, if you use automation to open a mail merge
document the data source will be unlinked - you have no choice but to
link up using code
- then you have to take care of executing the merge and making sure
you save/close the correct documents.

By the time you've done all this (using VBA, which you'd have to do as
mail merge has changed appreciably since the WordBasic days), you'll have
spent more time coding, and have a slower result, than polishing up your
existing bookmark code :-)
I have an application which needs to communicate with MS Word to
generate documents.
Typically my application will want to generate 1 document at a time.
The user will select a template name and then choose to build a
document.
My application then has the responsibility of populating the document
with values.
I have created document templates in MS Word which contain form fields.
I have given my fields bookmark names.
I am using COM automation to communicate with Word and I am using
WordBasic interface to call the functions I need performed.
I can start Word and give it a template to open. I then ask it for all
the bookmark names.
I then cycle through each bookmark and populate it via doing a 'GoTo'
bookmark followed by an 'Insert'. It all seems to be working.
Questions
1) what about using mail merge fields. Can I achieve the same thing
using a mail merge ? Is it any easier ? Do I need to build a data
source file containing all my data and then do a mail merge ?
2) the WordBasic interface is now old technology. What is a more modern
approach to achieving my requirements ?
3) In general what is the best approach to having my application
generate Word documents for my users ?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
 

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

Back
Top