0

我有 3 个字段地址、状态、报告日期的表单。

地址字段包含 mil 必须发送到的 ID。

现在我创建了一个代理,当状态不完整且报告日期正好是今天日期前 7 天时,它应该邮寄到地址字段中存在的数据。

我的代码:

Option Public
Option Declare

Sub Initialize
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim timestamp As New NotesDateTime("Today")
Dim Noresponsedate As NotesDateTime
Dim vw As NotesView
Dim diff As Integer
Dim SendTo As Variant

Call timestamp.SetNow()
Set db = sess.CurrentDatabase

Set vw = db.GetView( "data" )   
Set doc = vw.GetFirstDocument()
While Not doc Is Nothing    
If doc.Status(0) = "Incomplete" Then    
Call checktimedifference(doc)   
End if  
    Set doc = vw.GetNextDocument(doc)
  wend
End Sub

Sub checktimedifference(doc As NotesDocument)
Dim due As NotesDateTime
Dim present As NotesDateTime
Dim timecheck As variant
Set due = New NotesDateTime ( "" )
Set present = New NotesDateTime ( "Today" )
timecheck = doc.ReportingDate(0)
due.LSLocalTime = timecheck
If due.TimeDifference (present) = -604800 Then   
Call sendmailtouser(doc)     
End If  
End Sub
Sub sendmailtouser(doc As NotesDocument)
Dim db As NotesDatabase
Dim rtiitem As NotesRichTextItem
   Dim maildoc As NotesDocument
    dim recepient As variant    
  Set maildoc = New NotesDocument( db )
  Set rtiitem = New NotesRichTextItem( maildoc, "Body" )    
  recepient = doc.adress(0) 
  maildoc.from = db.Title
  maildoc.form = "memo"
  maildoc.subject = "A Minor Injury Report:" & doc.Seq_No(0) & " needs your response"
  maildoc.SendTo = recepient
   Call rtiitem.AppendText( "Please respond to this Minor Injury Report" )
  Call rtiitem.AddNewline( 2 )
   Call rtiitem.AppendText( "Your response for the Minor Injury Report: " &  doc.Seq_No(0) & " is required" )
   Call rtiitem.AddNewline( 2 )
   Call rtiitem.AppendText( "Please click on the following link to access the document.")
      Call rtiitem.AppendDocLink( doc, db.Title )   
     Call maildoc.Send(False)   
    End Sub

当我在客户端上运行代理时,出现以下错误:

在此处输入图像描述

请帮助我解决错误并将邮件发送给收件人。

4

1 回答 1

0

不使用任何错误处理是非常糟糕的做法。但是您的错误很可能发生在 sendmailtouser- 子程序中,您在其中调暗了名为 db 的本地 notesdatabase- 对象,而没有实际初始化它。

线

set maildoc = New NotesDocument( db ) 

将失败。要么全局声明 db 并将其设置在您的初始化中,要么再次在该 sub 中设置 db 并再次设置 db(最坏的情况是您必须为每个文档都这样做)

于 2013-05-27T17:08:29.910 回答