This is a repeat of a problem reported back in 2004
http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/e785c60c6e54930585256f3b0048f43a?OpenDocument
At issue is that the code tosses an entry not found in index error at the nav.getnext(entry) line. If I run the agent once, I'll pass through several thousand records before the error happens, run it again and it's a different number of records.
The view used is not being updated; docs are added to/removed from the db by a scheduled agent that runs once an hour and I'm running my clean up code when the scheduled agent is not running. Users don't have edit rights to the system.
Right now, I'm deleting docs from the folder right after the entry not found error stops the agent, then I'll start the agent up again.
Any ideas are appreciated.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim entry As NotesViewEntry
Dim nav As NotesViewNavigator
Dim doc As NotesDocument
Dim key As String
Dim dc As NotesDocumentCollection
Dim i As Integer
Set db = session.CurrentDatabase
Set view = db.GetView("vwReceiptsForDups")
Set nav = view.CreateViewNav
Set entry = nav.GetFirst
If entry Is Nothing Then Exit Sub
While Not(entry Is Nothing)
If entry.IsCategory And entry.IndentLevel = 0 Then
' Print "Processing: " & Key
key = entry.ColumnValues(0)
Set dc = view.GetAllDocumentsByKey(key)
If dc.Count > 1 Then
' Print "Moving dups for: " & Key
For i = 1 To dc.Count - 1
Set doc = dc.GetNthDocument(i)
Call doc.PutInFolder("fldDups")
Next
End If
End If
Set entry = nav.GetNext(entry) 'fails here.
Wend
Print
Messagebox "done"
End Sub