COM: How to use GetNextDocument(doc) when doc is deleted?

Hello,

I’m trying to cycle through a notesDocumentCollection using the following:

l_oDoc = l_oDocCol.GetFirstDocument()

DO WHILE !ISNULL(l_oDoc)					

	l_oNextDoc = l_oDocCol.GetNextDocument(l_oDoc)		

	IF !l_oDoc.IsDeleted()		

		l_oDoc.removePermanently(.T.)		

	ENDIF

	l_oDoc = l_oNextDoc

ENDDO 

But, if l_oDoc is deleted, I get an error on this line:

l_oDocCol.GetNextDocument(l_oDoc)	

Here’s the error message:

OLE IDispatch exception code 0 from NotesDocumentCollection: Argument has been deleted…

How can I get the next document when the current one is deleted?

Thanks.

Subject: flag and delete later, or get next before deleting

There are two ways to approach this:Flag and delete later:

Instead of actually deleting the document now, save a value to a field (i.e. doc.deleteme=Y). then later in the script, find all the documents with that flag and delete them.

Get next before deleting:

Looks something like this:

Set doc = collection.GetFirstDocument()

While Not(doc Is Nothing)

Set docnext = collection.GetNextDocument(doc)

(do stuff to doc, including possibly delete it)

Set doc = docnext

Wend