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

Show Userform - Mailmerge, a little help? :-) 2

Status
Not open for further replies.

PhilBell

Technical User
Dec 11, 2006
8
GB
Hi,

I'm working with a mail-merge document. I have a userform that allows the user to input a specific paragraph (the user is given a choice of paragraphs, and selects which one using a selection of commmand buttons, which inputs the paragraph in the relevant position on the document), I'd like to have the userform pop up at the same time my fill-in boxes pop up (when the document is first merged), but I am having difficulties finding the correct code to do this.

The userform is called NewOfferLetter, I have tried:
Private Sub NewOfferLetter_Initialize()
Load NewOfferLetter
NewOfferLetter.Show
End Sub

This line of code doesn't seem to display the userform, and if I try to use the form manually, I am presented with a Run-time error '5941' (The requested member of the collection does not exist) which presumably means I'm missing a rather important piece of code, and/or my code (shown above) is incorrect.

Any help is much appreciated.
 
Hi Phil,

Id suggest using an ASK field to solicit a response from the user as to whether to insert the particular paragraphs. For example, you could use fields codes like:

{ASK Option "Which version of the letter is needed? Insert 'A' for Version 1; 'B' for Version 2; 'C' for Version 3; or press 'Cancel' for the default."}

{IF{Option \* Upper}= "A" "Text for Version 1 goes here"}

{IF{Option \* Upper }= "B" "Text for Version 2 goes here"}

{IF{Option \* Upper }= "C" "Text for Version 3 goes here"}

You can put the various IF fields wherever you want, singly or in groups, depending on what combinations of optional text you want in a given situation. The output from a given IF field can itself include multiple paragraphs, including headings, etc.

Cheers

[MS MVP - Word]
 
Thanks for the advice macropod.

Out of interest, what is the code to prompt a userform to activate when a (word) document is opened?
 
Hi Phil,

Your code to load the userform looks OK to me.

I don't know if you're trying to run this before or after the merge has taken place, but if it's after and your userform uses bookmarks, then it's not going to work. That's because the bookmarks get deleted during the merge. The same applies to ASK fields.

Cheers

[MS MVP - Word]
 
The code for the userform does not look good to me.

Out of interest, what is the code to prompt a userform to activate when a (word) document is opened?
You can activate a userform when a document opens by using the Document_Open event.
Code:
Sub Document_Open()
   NewOfferLetter.Show

Every time the document is opened, NewOfferLetter userform will display (ie. load and show).

NewOfferLetter.Show fires Userform_Initialize. So your code:
Code:
Private Sub NewOfferLetter_Initialize()
    Load NewOfferLetter
    NewOfferLetter.Show
End Sub
IS the userform activating (or actually Initializing). Your code is doing this:

- something firing NewOfferLetter.Show, which loads and shows the userform. After it loads, it initializes and you are again loading it, and again showing it.

macropod and I have a running thing regarding the use of field. His field solution will of course work, and well. However, I would never do it that way, as I prefer userforms. Also, ASK requires the use of bookmarks. Mind you, I love bookmarks, but having the user make a choice on a userform allows the text to be put anywhere, not just a bookmark. I also find that updating any inserted text is easier on a userform, as everything is in one place.

Gerry
My paintings and sculpture
 
So i've been trying to get this form to work and like macropod explained, the bookmarks are being removed when the merge takes place, which has rendered the form useless.

How would I allow the user to input the specific paragraph where the bookmark originally was?
 
Hi Phil,

For anything using ASK fields and/or bookmarks to work, the edits have to be made *before* the merge takes place. See:
for full details, plus a possible workaround if working with formfields will suit your needs.

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top