Order of bookmarks from userform textboxes

M

Monica

I have a letter that includes several mostly-boilerplate
paragraphs (not all of which are included in every
instance of the letter). I created a userform with
checkboxes so the user can select which paragraphs need to
be included, and checking a checkbox enables some
textboxes so that the user can add some additional
pertinent info to the paragraph.

Why, oh why, can I not get these things to appear in the
proper order in my letter? I have an on-click event that
creates the letter, and it includes the following
(shortened up considerably to leave out the boring details
of the actual text, and excluding the textbox stuff that
goes into the paragraphs):

If frmMyForm.ChkProv = True Then
.Bookmarks("PROV").Range.Text = "A"
End If
If frmMyForm.ChkRule = True Then
.Bookmarks("RULE").Range.Text = "B"
End If
If frmMyForm.ChkMed = True Then
.Bookmarks("MED").Range.Text = "C"
End If
If frmMyForm.ChkExp = True Then
.Bookmarks("EXP").Range.Text = "D"
End If
If frmMyForm.ChkInc = True Then
.Bookmarks("INC").Range.Text = "E"
End If
If frmMyForm.ChkComments = True Then
.Bookmarks("COMMENTS").Range.InsertBefore "F"
End If

If I select more than one of the checkboxes and then
create the letter, it inserts the text options in reverse
order--for example, if I select all boxes, the letter says
FEDCBA instead of ABCDEF.

I have gotten it to put them in the correct order if I put
a space between each bookmark in the document, but then I
end up with a space before the first character in each
paragraph. How do I get Word to order these lovelies the
way *I* want them?

Thanks in advance.
 
M

Monica

Correction. Make that:
If frmMyForm.ChkComments = True Then
.Bookmarks("COMMENTS").Range.InsertBefore F
End If

where F is a textbox on the userform, the contents of
which are filled in by the user.
 
D

Doug Robbins - Word MVP

Hi Monica,

Instead of adding the paragraphs to the template using code, include all of
the paragraphs in the template with each one being enclosed in a bookmark
and in the order that you want them to appear and have your code delete the
unwanted paragraphs.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
M

Monica

Doug, as always, an elegant solution at light speed. I
appreciate your help.

--Monica
 

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

Top