Error to remove document

I have an agent who check my document: If my document isn’t valid, it delete document.

But they is an error:

“Function requires a valid ADT argument”

My agent is:

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument



Set db = session.CurrentDatabase

Set view = db.GetView( "absence_date" )

Set doc = view.GetFirstDocument



While Not (doc Is Nothing)

	If doc.GetItemValue("DateFin")(0)="" Then

		doc.Remove(True)

	End If

	

	Set doc = view.GetNextDocument(doc)

Wend

End Sub

Can you help me?

Subject: error to remove document

Sylvain,

It is the line at the end…

“Set doc=view.getnextdocument(doc)”

doc has been deleted, so Notes doesn;t have a placeholder to step to the next document from.

Just replace your view with a document collection (which is static) to avoid this error

HTH

Mike

Subject: error to remove document

thanks everyone

Subject: error to remove document

This is quite a common problem - a quick search of the forum may well have given you the solution.

Having said that, the problem is that once the document has been deleted, it’s no longer available for the view.getNextDocument(doc) call.

What you need to do is get the next document before you delete the current one:

set doc = view.getFirstDocument

while not doc is nothing

set nextDoc = view.getNextDocument(doc)

if doc.GetITemValue(“DateFin”)(0) = “” then

doc.remove(true)

end If

set doc = nextDoc

wend

HTH

Kiers

Subject: error to remove document

You’re deleting the document you rely on in the call to view.GetNextDocument()

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument Set db = session.CurrentDatabase

Set view = db.GetView( “absence_date” )

Set doc = view.GetFirstDocument While Not (doc Is Nothing)

If doc.GetItemValue(“DateFin”)(0)=“” Then

doc.Remove(True)

End If

'doc is nothing here if the ‘if’ condition was satisfied

Set doc = view.GetNextDocument(doc)

Wend

End Sub

One way around the problem is to use a temporary reference to hold the doc to be deleted, move to the next doc and delete it.

I prefer to create an empty notesdocument collection, add the documents to be deleted to it, and them remove them en masse at the end.

You should be setting view.AutoUpdate = False at the start too.