Problem transfering Button LS code to Agent

Dear All,

I have a code that transfers mail body contents to another database creating each document for each mail.

The code is working with the button but when i add it at a agent just doesn’t work.

Dim Session As New NotesSession

Dim db As NotesDatabase

Dim db2 As New NotesDatabase( "Server", "xxx.nsf" )

Dim ws As New NotesUIWorkspace

Dim doc As NotesDocument

Dim doc2 As NotesDocument

Dim rti As NotesRichTextItem

Dim rtnav As NotesRichTextNavigator

Dim rtrange As NotesRichTextRange

Dim iCount As Integer

Dim vSplit As Variant

Dim NewDoc As NotesDocument

Dim collection As NotesDocumentCollection



Set collection = db.UnprocessedDocuments

Set doc = collection.GetFirstDocument()



While Not(doc Is Nothing)

	

	

'Set doc = ws.CurrentDocument.Document

	Set rti = doc.GetFirstItem("Body")

	Set rtnav = rti.CreateNavigator

	Set rtrange = rti.CreateRange

	

	

	Set session = New NotesSession

	Set db = Session.CurrentDatabase

	Set Newdoc = New NotesDocument( db )

	

	Set doc2 = New NotesDocument ( db2 )

	doc2.Form = "MainForm"

	Newdoc.Form = "Memo"		

	

	If rtnav.FindFirstElement(RTELEM_TYPE_TEXTRUN) Then

		Do

			iCount = iCount + 1

			

			Call rtrange.SetBegin(rtnav)

			

			vSplit = Split(rtrange.TextRun, Chr(9))

			

			If icount = 2 Then

				

				doc2.Title = vSplit(Ubound(vSplit))

				

                etc........

				

			End If

			

		Loop While rtnav.FindNextElement(RTELEM_TYPE_TEXTRUN)

		

		Call doc2.Save(False,True)

	End If

	

	Call session.UpdateProcessedDoc( doc )

	Set doc = collection.GetNextDocument(doc)	

Wend

This error is critical for me and i don’t know why doesn’t work(Maybe the UnprocessedDocuments faults?)

Thanks in advance

Subject: Problem transfering Button LS code to Agent

Hi,

You shd set your db before the line “Set collection = db.UnprocessedDocuments”.

Without setting database you cannot get the collection.

:slight_smile: