手动运行(右键单击并运行)时的代码可以正常工作,但是使用计划表自动执行时会出现问题。 自动化后,代码可以正常运行,但是恰好在代码运行结束时失败,并显示上述错误消息。
代码看起来不错,可以按需设置变量,手动完成后代码可以正常运行。
Sub processJobs(dbCurrent As NotesDatabase)
Dim vwLookup As NotesView
Dim docReq As NotesDocument
Dim dtMonthAgo As New NotesDateTime(Today)
Dim dtDelDate As NotesDateTime
Dim itmDelDate As NotesItem
Dim sender As NotesName
Dim receiver As NotesName
Dim nmServer As NotesName
Dim lngNoOfDays As Long
Dim mail As Email
Dim intCount As Integer
Dim intCountFailed As Integer
Dim strSendTo As String
On Error GoTo ErrorHandler
On Error 4000 GoTo RecipientNameBlank
On Error 4294 GoTo RecipientNotInNAB
Call AgentLog.LogAction("--------- Process Job ---------")
Call dtMonthAgo.AdjustMonth( -1 ) ' set the dtMonthAgo date to one month ago
Call dtMonthAgo.Setanytime() ' remove the time component from the date
Set vwLookup = dbCurrent.Getview("JobView")
vwLookup.Autoupdate = False
Set docReq = vwLookup.Getfirstdocument()
intCount = 0
intCountFailed = 0
Do Until docReq Is Nothing
Set itmDelDate = docReq.GetFirstItem("DeliveryDate")
If itmDelDate.Type = 1024 Then
Set dtDelDate = itmDelDate.DateTimeValue
Call dtDelDate.SetAnyTime
If dtMonthAgo.TimeDifference(dtDelDate) > 0 Then
intCount = intCount + 1
Set mail = New Email ' send email...
mail.Subject = "Processed Job"
mail.HTML = getCompletionHTML(docReq, mail.WebURL)
Set sender = New NotesName(docReq.JobBy(0))
Set receiver = New NotesName(docReq.DespatchTo(0))
Set nmServer = New NotesName(dbCurrent.Server)
If receiver.Organization = nmServer.Organization Then
strSendTo = receiver.Abbreviated
' send a copy to..
If sender.Abbreviated <> receiver.Abbreviated Then
mail.CopyTo = docReq.JobBy(0)
End If
Else
strSendTo = sender.Abbreviated
End If
mail.Send(strSendTo)
Call agentLog.LogAction(strSendTo & " - Job No: " & docReq.JobNo(0))
flagDoc:
' flag the job...
Call docReq.Replaceitemvalue("CompletionJob", "Y")
Call docReq.Replaceitemvalue("CompletionJobDate", Now)
Call docReq.Save(True, False)
End If
End If
Set docReq = vwLookup.Getnextdocument(docReq)
Loop
Call AgentLog.LogAction("")
Call AgentLog.LogAction("Attempted to send " & CStr(intCount) & " Job")
Call AgentLog.LogAction("Failed to send " & CStr(intCountFailed) & " Job")
Call AgentLog.LogAction("--------- End of job process ---------")
ErrorHandler:
If Not AgentLog Is Nothing Then
Call AgentLog.LogError(Err, "errorHandler: " & CStr(Err) & " " & Error$ & " in " & LSI_Info(2))
End If
Resume getOut
23/05/2019 00:00:05 errorHandler: 91 Object variable not set in PROCESSJOBS(Object variable not set)
应该使代理遍历视图,获取收件人的名字,设置变量,然后自动发送电子邮件。 通过自动化,它确实遍历了视图和收件人的获取/设置名称,但是在获得未设置对象变量的姓氏后立即失败。 手动运行代码根本没有问题,但是此代码需要自动运行。
答案 0 :(得分:2)
在您的ErrorHandler中,记录(或打印)发生错误的行。
ErrHandler:
Print "Got error " & Error$ & " on line " & cstr(Erl)
从IBM
复制的示例答案 1 :(得分:1)
您需要一个Exit Sub语句来防止您的代码陷入错误处理程序中。
Call AgentLog.LogAction("")
Call AgentLog.LogAction("Attempted to send " & CStr(intCount) & " Job")
Call AgentLog.LogAction("Failed to send " & CStr(intCountFailed) & " Job")
Call AgentLog.LogAction("--------- End of job process ---------")
Exit Sub ' **** You need this
ErrorHandler:
If Not AgentLog Is Nothing Then
Call AgentLog.LogError(Err, "errorHandler: " & CStr(Err) & " " & Error$ & " in " & LSI_Info(2))
End If
Resume getOut
您似乎也没有初始化AgentLog,尽管这可能是全局的。在按计划运行代理日志时,是否成功将这些行写入了代理日志?如果不是,则访问计划在其上的服务器上的代理日志数据库可能存在问题。