Mail Merge with Form Data

Clif
Clif used Ask the Experts™
on
Writing in Word 2010 for users who are running Word 2003

I have a Mail Merge document that's working well, pulling data out of the database and placing it where it needs to be.

Now I need to ask the user a couple of questions and place some text in certain places where it needs to be depending on the answer.  To that end, I have created a form with two combo boxes listing all the available choices and an OK button.  The user makes a selection, clicks OK and ...

Now what?

I know the values I want entered, but what's the code to move them from the btnOK_Click event to the doc file?

I was hoping the values would appear as variables that I could drop in like I am currently doing with mail merge fields.

How Do I?

TIA
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
GrahamSkanRetired
Top Expert 2012

Commented:
The main problem in adding data to a document is knowing where to put it.

One way is to use a bookmark:

ActiveDocument.Bookmarks("MyBookmark").Range.Text = cboQuestion1.Text
GrahamSkanRetired
Top Expert 2012

Commented:
However I am not sure that the approach is suitable for use with mail merge.

Not that you can use an ASK field to allow the user to add some text to each record's output during a mail merge.
GrahamSkanRetired
Top Expert 2012

Commented:
Oops.

"Not that you can ..."
should read:
"Note that you can ..."
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Author

Commented:
I thought about using "Ask", but I need it to be in the form of a combobox (ie, a specific number of selections and no mis-spellings).  And, it looked like (from my research) that "Ask" was only available in Word 2010 (and possible 2007).

I tried the bookmark, and it does sort of work in that text is inserted in the document where I need it to go (just like my previous question, I am putting the data in a textbox on the document so that it doesn't move the existing text during an insert.  The biggest issue, though, is, that there is no way to "clear" the bookmark items so the user would have to close Word and restart it for each document.
Retired
Top Expert 2012
Commented:
If you need existing text to be replaced when adding bookmark text, you need to make sure that the bookmark 'contains' the text to be replaced. In code, you have to get the range, set its text and then add the bookmark for the range.


Dim rng as range

set rng = ActiveDocument.Bookmarks("MyBookmark").Range
rng.text = cboQuestion1.Text
activedocument.Bookmarks.Add "MyBookmark", rng

Open in new window

Author

Commented:
Perfect.  Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial