Hi,I try to run an agent so it will populate the field “correspondence_num” in all documents in a view. I kept getting type mismatch at line "
docno = docLU.Correspondance_Num(0)
Correspondance_Num is a number field, editable
Here’s the who codes for the agent.
Thanks for any help
Michelle
Sub Initialize
Set session=New NotesSession
Set db_current = session.CurrentDatabase
’ Get Correspondence DB
tmpPath=db_current.filepath
flname=Format(db_current.filename,"<")
serverName=db_current.server
pos=Instr(1,Format(tmpPath,"<"),flname)
pathName=Mid(tmpPath,1,pos-1)
Dim db_docs As New NotesDatabase (serverName,pathName+"Correspondance.nsf")
Dim doc_docs As NotesDocument
’ Search Correspondence db for blank ID fields
Dim dateTime As New NotesDateTime("12/01/2001")
searchFormula$ = "Correspondance_Num = """""
Dim coll_docs As NotesDocumentCollection
Set coll_docs = db_docs.Search(searchFormula$,dateTime,0)
’ If docs found
If coll_docs.count > 0 Then
Dim doc As NotesDocument
Dim viewLU As NotesView
Dim docLU As NotesDocument
Dim docno As Long
’ Get last used number from CorrespondanceNum view
Set viewLU = db_docs.GetView("CorrespondenceView")
Set docLU = viewLU.GetFirstDocument
docno = docLU.Correspondance_Num(0)
’ Get the first document in the mass merge collection
Set doc = coll_docs.GetFirstDocument()
’ Spin through all documents and set Correspondence_Num appending 1 each time.
i = 0
While i < coll_docs.count
docno = docno+1
Call doc.ReplaceItemValue("Correspondance_Num", docno)
Call doc.Save( True, False )
Set doc = coll_docs.GetNextDocument(doc)
i = i+1
Wend
End If
End Sub