Keep getting "Type Mismatch" in my agent

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

Subject: Keep getting “Type Mismatch” in my agent

try dim’ing docno as integer

also on this line:

docno = docLU.Correspondance_Num(0)

write this instead:

docno = cint(docLU.Correspondance_Num(0))

hope this helps

ST

Subject: RE: Keep getting “Type Mismatch” in my agent

Hi Stephen,I did like you said and I still get the “Type mismatch” error.

Michelle

Subject: RE: Keep getting “Type Mismatch” in my agent

debug and see what the value of that field is:

docno = docLU.Correspondance_Num(0)

im guessing it’s either null (blank) or has some sort of string that cannot be converted to a number.

ST

Subject: RE: Keep getting “Type Mismatch” in my agent

Right now the field is blank so that’s why I want to put a sequential numbers for each document that’s in the view. The line docno = docLU.Correspondance_Num(0) gives an error message so I cannot see its vale.M

Subject: RE: Keep getting “Type Mismatch” in my agent

if the last used number is currently blank then write an IF statement to conver the blank to a useable value, like zero or one:

if cstr(docLU.Correspondance_Num(0)) = “” Then

docno = 0

else

docno = cint(docLU.Correspondance_Num(0))

End IF

Subject: RE: Keep getting “Type Mismatch” in my agent

That was the solution. Thanks Stephen.M