RenderToRTItem and While Loop Not rendering all docs in the view to my RT field

Any help is greatly appreciated.

On a form I have a button (see my code below) that populates a RT field on my form with renderings of docs grabbed from a view (I create tempdocs first from my view docs in order to remove unwanted fields). Using debugger the While loop is grabbing the docs correctly and no errors are occurring in my code.

My issue is that only the last 2 or 3 docs in the view are being rendered in my RT field out of a total of 15 docs in the view.

------------code snippet-----------

Sub Click(Source As Button)

Dim session As New notessession

Dim workspace As New notesuiworkspace

Dim db As notesdatabase

Dim view As notesview

Dim doc As notesdocument

Dim db2 As New NotesDatabase(“”,“”)

Dim doc2 As notesDocument

Dim x As Integer

Dim tempdoc As notesDocument

Dim richStyle As NotesRichTextStyle

Dim body As NotesRichTextItem

Set db = session.CurrentDatabase

Set db2 = session.getdatabase(“”,“TestDatabase.nsf”)

Set view = db2.getview(“(ItemsPastWeek)”)

Set uidoc = workspace.currentdocument

Set doc = uidoc.Document

'RICH TEXT ITEM

Set body = New NotesRichTextItem ( doc, “MyRTBody” )

Set richStyle = session.CreateRichTextStyle

Set rtpStyle = session.CreateRichTextParagraphStyle

richStyle.FontSize = 10

richStyle.Bold = False

richStyle.NotesFont = body.GetNotesFont(“Arial”, True)

Call body.AppendStyle(richStyle)

x=6

Set doc2 = view.GetFirstDocument

While Not ( doc2 Is Nothing )

Set tempdoc = New NotesDocument( db )

Call doc2.CopyAllItems( tempdoc, True )

tempdoc.Form = “BIP”

Call tempdoc.Save( True, True )

Call body.AppendText("Page " & Cstr(x))

Call body.AddNewLine( 1 )

Call tempdoc.RenderToRTItem(body)

Call body.AddNewLine( 1 )

Call body.AddPageBreak

x = x +1

Call tempdoc.RemovePermanently(True)

Set doc2 = view.GetNextDocument( doc2 )

Wend

Call uidoc.save

Call doc.save(False,True)

Call uidoc.close

Exit Sub

End Sub

Subject: RenderToRTItem and While Loop Not rendering all docs in the view to my RT field

Nevermind… I figured it out. Once I took my button code out of the document itself and added it to a view level button action it worked just fine…