Object Variable not set

Hello,

I am running following agent which will remove duplicate docs from a view.

I am facing following problem.

If duplicate docs are more than 2 in a view, then i get an error “Object varibale not set”.

When I debug the code, Debuger shows an error on line " Call doc.Remove(True) ".

It works fine if there are 2 docs for the same reqnumber in a view, but if there are more than 2 docs it gives an error. can any one guide me what could be the problem.

Sub Initialize

Dim ns As New NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim view As NotesView

Dim doc As NotesDocument

Set db = ns.CurrentDatabase

Set view = db.GetView(“DUP”)

Set doc = view.GetFirstDocument

While Not ( doc Is Nothing )

reqnum = doc.OBSRequestNumber(0)  

Set NextDoc = view.GetNextDocument(doc)

Call DeleteDuplicateDocs ( Cstr(reqnum), db, doc )			

Set Doc = NextDoc				

Wend

End Sub

Function DeleteDuplicateDocs ( reqnum As String,

db As notesdatabase, doc As NotesDocument )

Dim j As Integer

Dim view As NotesView

Set view = db.GetView(“Duplicate\Latest Modified”)

j = view.FTSearch( reqnum , 0 )

If j > 1 Then

count = j - 1

For i = 1 To count

	Call doc.Remove(True)

	Next									

End If	

End Function

Subject: Object Variable not set

it seems doc variable couldn’t set in that function during script is running

Subject: Object Variable not set

Hi Manish,

Change your code a bit, then it will work. Don’t use while, use DO (but that is only a style thing). You run into the error when your next document contains the same reqnum!

set doc = view.Getfirstdocument

set nextdoc = doc

Do until Doc is nothing

reqnum = doc.OBSRequestNumber(0)

Do until nextDoc is nothing

  if nextDoc.OBSRequestNumber(0) <> reqnum then

     exit do

  end if

  Set NextDoc = view.GetNextDocument(doc)

end do

Call DeleteDuplicateDocs ( Cstr(reqnum), db, doc )

set doc = nextdoc

End do

Hope that helps!

:wink: stw

P.S.: I find “do until doc is nothing” much more readable than “do while not doc is nothing”