Why GetNextDocument loses RTItem value just set?

This has me completely baffled…I have documents that have graphics on them that I want to use in a document that I am building in Lotus script. So I created keyword documents to hold the graphics so I can use the AppendRTItem method to include them in the new document.

Here’s the mystery to me. If I set my Lookups to do one by one. No problem, the global RTitems get set and I can use them and all is perfect. But if I use the code below, and get a collection of documents, this doesn’t work. The comgraphic and notcomgraphic items get set properly, but when I watch them in debug, when it executes the Set ludoc = dc.GetNextDocument( ludoc), the value it has just set disappears. Why??? What am I missing here?

Any insight would be greatly appreciated.

Global Declarations

Dim comgraphic As NotesRichTextItem

Dim notcomgraphic As NotesRichTextItem

'Now go get the completed graphic

Set luview = db.GetView( "(Keyword Documents)" )

Set dc = luview.GetAllDocumentsByKey( "Graphic", True )

Set ludoc = dc.GetFirstDocument

While Not ( ludoc Is Nothing)

	Select Case ludoc.KeywordKey(0)

	Case "Completed"

		Set comgraphic = ludoc.GetFirstItem( "KeywordNotes" )

	Case "Not Complete"

		Set notcomgraphic = ludoc.GetFirstItem( "KeywordNotes" )

	End Select

	Set ludoc = dc.GetNextDocument( ludoc )

Wend

Subject: Why GetNextDocument loses RTItem value just set?

I think you’ve answered your own question: you loose the reference to the rtItem on ludoc when you move onto the next ludoc because the rtitem object is only available via the ludoc.

You would need to append the rtItems to their destination (if this is what you are doing) BEFORE you do getnextdoc

Subject: Why GetNextDocument loses RTItem value just set?

A notesitem or notesrichtextitem can exist only in the context of a notesdocument. When the notesdocument passes out scope so does the notesitem.

Subject: RE: Why GetNextDocument loses RTItem value just set?

Thank you! Now it makes sense and I guess I’ll create NotesDocument objects to match the graphics that I need so that I can use them multiple times without having to go retrieve them each time I need them.

Thanks again.

Subject: RE: Why GetNextDocument loses RTItem value just set?

As a suggestion, create a shared folder. remove all the documents from the folder at the start of your code (NB: don’t use Removeall/remove as this will delete them!!! use removefromfolder) and then add the ones you want into the folder one by one (putinfolder). You can then access them from the folder any time you want until you clear it the next time.