Issue with “Search” and “RemoveAll” method

I have recently faced a problem while working with “Search” and “RemoveAll” methods.

Scenario: There were total 40,000 documents needs to be deleted from a notes database. But my requirement is to delete the documents in chunks(5000 in one run) and send email everytime.

code to implement the above scenario:

Sub Initialize

On Error Goto errorhandler

Dim session As New NotesSession

Dim thisdb As NotesDatabase

Dim DocColl As NotesDocumentCollection

Dim SearchStr As String



SearchStr = | _MarkForDelete != ""|

Set thisdb = session.CurrentDatabase

If Not thisdb Is Nothing Then

  Set DocColl=thisdb.Search(SearchStr,Nothing,5000)

    If DocColl.Count>0 Then

      Call DocColl.RemoveAll(1)

    End If

End If

-- code for mailing goes here, i have taken coll count in a variable an used it in email ----            

End Sub

This above code deleted all the documents in one run but sent an email saying it has deleted 5000 documents.

Does anyone has idea, why it happened???

Thanks in advance.

Subject: Yes, count doesn’t work the way it should or expect it to…

I found this a few years ago: