Please help. This is my code. It sometimes run and sometimes pops up with “object variable not set”. This is a agent scheduled to run on the server daily.
Sub Initialize
Dim se As New NotesSession
Dim db As NotesDatabase
Dim vw As NotesView
Dim vdoc As NotesDocument
Dim mdoc As NotesDocument
Dim it1 As NotesItem
Dim it2 As NotesItem
Dim it3 As NotesItem
Dim dt1 As New NotesDateTime (Today)
Dim dt2 As NotesDateTime
Dim tv As Double
Dim cont As Variant
Set db = se.CurrentDatabase
Set vw = db.GetView("SIActive")
Set vdoc = vw.GetFirstDocument
While Not (vdoc Is Nothing)
’ For i = 1 To 63
For i = 1 To 57
Set it1 = vdoc.GetFirstItem("b1s" + Cstr(i))
If it1.Values(0) <> "" Then
Set it2 = vdoc.GetFirstItem("b1i" + Cstr(i))
Set it3 = vdoc.GetFirstItem("b1st" + Cstr(i))
If it2.Values(0) = "" And it3.Values(0)<>"N/A" Then
Set dt2 = it1.DateTimeValue
tv = (dt1.TimeDifference(dt2) / 86400)
If tv = -2 Then
Set mdoc = New NotesDocument(db)
Set it1 = New NotesItem(mdoc, "SendTo", "", NAMES)
Call it1.AppendToTextList(vdoc.GetFirstItem("b1v"+Cstr(i)))
’ Call it1.AppendToTextList(vdoc.author(0))
’ Call it1.AppendToTextList(vdoc.authorb(0))
Set rtitem = New NotesRichTextItem ( mdoc, "Body" )
mdoc.form = "Memo"
mdoc.subject = "Serial introduction requires action - " + vdoc.contnum(0)
’ mdoc.body = “The above serial number is due for completion in 2 days, please action the section delegated to you.”
Call rtitem.AppendText ( "The above serial number is due for completion in 2 days, please action the section delegated to you.")
Call rtitem.AddNewline(1)
Call rtitem.AppendText ( "You can see the document by clicking on the added DocLink.")
Call rtitem.AddNewline(1)
Call rtitem.AppendDocLink( vdoc, db.Title )
Call mdoc.Send(False)
End If
If tv = 0 Then
Set mdoc = New NotesDocument(db)
Set it1 = New NotesItem(mdoc, "SendTo", "", NAMES)
Call it1.AppendToTextList(vdoc.GetFirstItem("b1v"+Cstr(i)))
Call it1.AppendToTextList(vdoc.author(0))
Call it1.AppendToTextList(vdoc.authorb(0))
Set rtitem = New NotesRichTextItem ( mdoc, "Body" )
mdoc.form = "Memo"
mdoc.subject = "Serial introduction requires action - " + vdoc.contnum(0)
Call rtitem.AppendText ( "The above serial number is due today and requires attention, please action the section delegated to you.")
Call rtitem.AddNewline(1)
Call rtitem.AppendText ( "You can see the document by clicking on the added DocLink.")
Call rtitem.AddNewline(1)
Call rtitem.AppendDocLink( vdoc, db.Title )
’ mdoc.body = “The above serial number is due today and requires attention, please action the section delegated to you.”
Call mdoc.Send(False)
End If
If tv = 2 Then
Set mdoc = New NotesDocument(db)
Set it1 = New NotesItem(mdoc, "SendTo", "", NAMES)
Call it1.AppendToTextList(vdoc.GetFirstItem("b1v"+Cstr(i)))
Call it1.AppendToTextList(vdoc.author(0))
Call it1.AppendToTextList(vdoc.authorb(0))
Set rtitem = New NotesRichTextItem ( mdoc, "Body" )
mdoc.form = "Memo"
mdoc.subject = "Serial introduction is overdue and requires action - " + vdoc.contnum(0)
Call rtitem.AppendText ( "The above serial number is 2 days overdue and requires attention, please action the section delegated to you.")
Call rtitem.AddNewline(1)
Call rtitem.AppendText ( "You can see the document by clicking on the added DocLink.")
Call rtitem.AddNewline(1)
Call rtitem.AppendDocLink( vdoc, db.Title )
’ mdoc.body = “The above serial number is 2 days overdue and requires attention, please action the section delegated to you.”
Call mdoc.Send(False)
End If
If tv = 5 Then
Set mdoc = New NotesDocument(db)
Set it1 = New NotesItem(mdoc, "SendTo", "", NAMES)
Call it1.AppendToTextList(vdoc.GetFirstItem("b1v"+Cstr(i)))
Call it1.AppendToTextList(vdoc.author(0))
Call it1.AppendToTextList(vdoc.authorb(0))
Call it1.AppendToTextList(vdoc.Manager(0))
Call it1.AppendToTextList(vdoc.SE_Koordinator(0))
Set rtitem = New NotesRichTextItem ( mdoc, "Body" )
mdoc.form = "Memo"
mdoc.subject = "Serial introduction is overdue and requires action - " + vdoc.contnum(0)
Call rtitem.AppendText ( "The above serial number is 5 days overdue and requires attention, please action the section delegated to you.")
Call rtitem.AddNewline(1)
Call rtitem.AppendText ( "You can see the document by clicking on the added DocLink.")
Call rtitem.AddNewline(1)
Call rtitem.AppendDocLink( vdoc, db.Title )
’ mdoc.body = “The above serial number is 5 days overdue and requires attention, please action the section delegated to you.”
Call mdoc.Send(False)
End If
End If
End If
Next
cont = True
’ For i = 1 To 63
For i = 1 To 57
Set it1 = vdoc.GetFirstItem("b1m" + Cstr(i))
If it1.Values(0) <> "" Then
Set it2 = vdoc.GetFirstItem("b1i" + Cstr(i))
Set it3 = vdoc.GetFirstItem("b1st" + Cstr(i))
If it2.Values(0) = "" And it3.Values(0)<>"N/A" Then
’ If it2.Values(0) = “” Then
cont = False
End If
End If
Next
If cont Then
Set mdoc = New NotesDocument(db)
Set it1 = New NotesItem(mdoc, "SendTo", "", NAMES)
Call it1.AppendToTextList(vdoc.author(0))
Call it1.AppendToTextList(vdoc.authorb(0))
Set rtitem = New NotesRichTextItem ( mdoc, "Body" )
mdoc.form = "Memo"
mdoc.subject = "Serial introduction items complete - " + vdoc.contnum(0)
Call rtitem.AppendText ( "All the items on the above serial number have been completed.")
Call rtitem.AddNewline(1)
Call rtitem.AppendText ( "You can see the document by clicking on the added DocLink.")
Call rtitem.AddNewline(1)
Call rtitem.AppendDocLink( vdoc, db.Title )
’ mdoc.body = “All the items on the above serial number have been completed.”
Call mdoc.Send(False)
End If
Set vdoc = vw.GetNextDocument(vdoc)
Wend
End Sub