Adding a paragraph through MS ACCESS vba

B

Basil.Shall

I am creating a word document using MS Access.

I am able to take data from a table (A memo field) and place it into a
document. The memo field has two paragraphs.

When I come to add the next paragraph through VBA, it overwrites the
last paragraph of the memo field. (i.e. only 1 paragraph from the memo
field can be seen in the document followed by the new text).

Can anyone advise how to stop VBA from overwriting the last para?

Thanks
 
S

StevenM

To: Basil,

It would help if you would tell us how you are adding text to a word document.

Nonetheless, the following codes offers an example.

Sub AddText()
Dim newDoc As Document
Dim oRange As Range
'The next line is very long.
Const sLorem As String = "Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum."

Set newDoc = Documents.Add
Set oRange = newDoc.Range

'Here are two styles of adding a paragraph mark.
'The first adds vbCr to the text string.
'The second adds a paragraph after
'Both must be followed by a Collapse
'in order to add more text.
With oRange
.LanguageID = wdNoProofing
.Text = "(1) " & sLorem & vbCr
.Collapse wdCollapseEnd
.Text = "(2) " & sLorem
.InsertParagraphAfter
.Collapse wdCollapseEnd
.Text = "(3) " & sLorem
End With
End Sub

Steven Craig Miller
 
D

Doug Robbins - Word MVP

Why insert the data one paragraph at a time?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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