ActiveDocument.Bookmarks().Range.InsertBefore not working as expected in MSWord UseForm

Why oh why, does the below ActiveDocument.Bookmarks().Range code;  

1) add an empty line before the inserted text
2) does not bullet the second insert
3) keeps the bookmark on the first line (shouldn't it have inserted "before" the bookmark?)

HELP!!!!
'CHECK REQUIREMENTS
If IsEmpty(Me.lbRequirements.Text) Then
    ' Do Nothing
Else
    Dim x As Long
    'Cylcle through each item in the listindex
    For x = 1 To Me.lbRequirements.ListCount - 1
        'If the item is selected add it to the document with a line return
        If Me.lbRequirements.Selected(x) Then
            ActiveDocument.Bookmarks("Requirements").Range.InsertBefore lbRequirements.List(x)
            ActiveDocument.Bookmarks("Requirements").Range.ListFormat.ApplyBulletDefault
            ActiveDocument.Bookmarks("Requirements").Range.InsertParagraph
        End If
    Next x
End If

Open in new window

Results of insert Results of insert
DahriaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
1.  This code line creates the empty document line
    ActiveDocument.Bookmarks("Requirements").Range.InsertParagraph

2. According to your pictures it does bullet the second line

3. I would add text and in a paragraph like this:

ActiveDocument.Bookmarks("Requirements").Range.InsertBefore lbRequirements.List(x) & VbCr




 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DahriaAuthor Commented:
Thank-y:o)u Graham,

1)  I removed the ActiveDocument.Bookmarks("Requirements").Range.InsertParagraph

2)  Was refering to the second "insert".  There are three inserts from the "Requirements" array;  Beneficiary Designation, Notarized Will Searches and Notarized Will.  The second insert... Notarized Will Searches is still not bulletted. (see new image attached)

3)  Added the "& VbCr"  after the InsertBefore to create new line

 New inserts New inserts
0
DahriaAuthor Commented:
Aaaaahhhh... found the solution to issue 2)...

I removed the bullet formatting from the code and applied it directly to the template.  This then includes the vbCR for the first "inserted" line only.  So added a If/Else check for the first insert and applied vbCR to all subsequent inserts. (see below code snippet)

 
'CHECK REQUIREMENTS
If IsEmpty(Me.lbRequirements.Text) Then
    ' Do Nothing
Else
    Dim x As Long
    Dim z As Long
    'Cylcle through each item in the listindex
    For x = 0 To Me.lbRequirements.ListCount - 1
        'If the item is selected add it to the document with a line return
        If Me.lbRequirements.Selected(x) Then
            If z = 0 Then
                ActiveDocument.Bookmarks("Requirements").Range.InsertAfter lbRequirements.List(x)
                z = 1
            Else
                ActiveDocument.Bookmarks("Requirements").Range.InsertAfter lbRequirements.List(x) & vbCr
            End If
        End If
    Next x
End If

Open in new window


Thank-you again Graham for pointing me in the right direction.

:o)
0
GrahamSkanRetiredCommented:
If that works, go with it.

It wasn't easy to see exactly where you were starting from (Picture.Value < 1000Words.Value), or what the full objective was.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.