What am I doing wrong? Insert Break

K

Kim

I am very new at working with VBA and programming word documents.

What I am doing is connecting to a database and looping through a recordset.

the recordset contains one field. I want to build a single word document
with each field on its own page.
I have it all working with one exception - the page break.


I cannot grasp what I am doing wrong. It seems that it should be easy - but
I am missing the bigger picture - somewhere -
here is what I have.


Can someone take pity on me and show me the error of my ways?

Thanks in advance.

oDoc is the Word.Document object
eRS is the recordset I am looping through
myRange is a Word.Range object
------------------------------------------------------

If Not eRS.EOF Then
Do While Not eRS.EOF
With oDoc
.Content.Font.Name = "courier"
.Content.InsertAfter Text:=eRS("text").Value
End With

Set myRange = ActiveDocument.Range
With myRange
.Collapse wdCollapseEnd
.End = ActiveDocument.Range.End
.Collapse wdCollapseEnd
.InsertBreak wdPageBreak
End With

With oDoc
.SaveAs FileName:=strFolder & strFilePre & ".Doc"
End With

eRS.MoveNext
Loop

End If

------------------------------------------------------
 
D

Doug Robbins

Seems to me like you are trying to re-invent the wheel. Did you consider
using mailmerge?

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
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