Agent Script to select document with StatusField="Allocated"

I am writing a script to select document with StatusField=“Allocated”, once found, it will refresh the document and save it, it will do this until the last document in the view.

However, I will appreciate some guidance on the script below, I get some sample codes, but not sure how to combine them to achieve the above objective, any help is greatly appreciated.

Sub Click(Source As Button)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim j As Integer

Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments

For j = 1 To collection.Count

Set doc = collection.GetNthDocument( j )

doc.Status = "Actual"

Call doc.Save( False, True )

Next

End Sub

Sub Exiting(Source As Field)

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument

Call uidoc.Refresh

End Sub

Subject: Agent Script to select document with StatusField=“Allocated”

create this agent , and run it

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim formula As string

Set db = session.CurrentDatabase

Formula=|Status=“Allocated”|

Set collection = db.Search(Formula, nothing,0)

det doc=collection.getfirstdocument

while not doc is nothing

doc.Status = “Actual”

Call doc.Save( False, True )

set doc=collection.getnextdocument(doc)

Wend

Subject: RE: Agent Script to select document with StatusField=“Allocated”

Tqvm, really appreciates that. Will let you know should I encounter any problem.

Subject: RE: Agent Script to select document with StatusField=“Allocated”

I tried to just copy and paste it at script programming pane, and get error message illegal executable code outside procedre at line “Set de =session.CurrentDatabase”. Need time to troubleshoot this first.tq