Agent to update docs in a view

I have a view full of about 40 documents. I want to loop through them an open/edit/save each one so that a QuerySave action happens that does a bunch of other stuff.

I built the following code which generates an error that I believe is caused by the line

Call UserUIDocument.Close

If I REM out that line everything works but I end up with all the documents open.

The error is “Error 4429: Unable to defer document close”

any ideas?

==========================================

Sub Initialize

Dim Session As New NotesSession

Dim DB As NotesDatabase

Dim NoteCollection As NotesDocumentCollection

Dim UserUIDocument As NotesUIDocument

Dim UserUIWorkspace As New NotesUIWorkspace



Dim dateTime As New NotesDateTime( "12/01/94" )

Dim NoteDoc As NotesDocument



On Error Goto HandleErr



Set DB = Session.CurrentDatabase 

searchFormula$ = "Form = ""Category"""

Set NoteCollection = DB.Search( searchFormula$, dateTime, 0)



Set NoteDoc = NoteCollection.GetFirstDocument



For i = 1 To NoteCollection.Count

	Set UserUIDocument = UserUIWorkspace.EditDocument( True, NoteDoc)

	Call UserUIDocument.Save 

	Call UserUIDocument.Close		

	Set NoteDoc = NoteCollection.GetNextDocument(NoteDoc)

Next



Msgbox "This agent has worked with " & NoteCollection.Count & " Notes." & Error, 0 + 48, "System Message"



Exit Sub

’ Error Handling

HandleErr:

Msgbox "Unknown error:" & Chr(10) & Chr(10) & "Error Num: " & Err() & Chr(10) & "Description: " & Error, 0 + 48, "System Message"



Exit Sub ' Exit when error occurs

End Sub

Subject: Solved: Agent to update docs in a view

There is a nifty new feature in N6 that does an immediate close and it works great for my purpose.

Call notesUIDocument.Close( [ immediate ] )

Parameters

immediate

Boolean. Optional. If True, the document is immediately closed. The default is False.

Note This parameter is new with Release 6.

Scott

Subject: RE: Solved: Agent to update docs in a view

It would be a lot quicker to do this in the back-end though; simply place the Querysave code in a library / agent, and run that over selected documents.

htp://www.benpoole.com