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
------------------------------------------------------
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
------------------------------------------------------