2013-05-27 84 views
0

我有3個字段的地址,狀態,ReportingDate的形式。剩餘郵件代理

地址字段包含密鑰必須發送的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 

當我運行在客戶端代理我收到以下錯誤:

enter image description here

請幫我解決了錯誤,併發送郵件到受助。

+0

在調試器中運行代碼以確定哪一個代碼正在生成錯誤,並相應地更新您的問題。然後有人可能真的能夠幫助你。它可能也會幫助你說出你使用的是什麼版本的Lotus Notes。 –

回答

0

不使用任何錯誤處理是非常糟糕的做法。但是你的錯誤很可能發生在sendmailtouser-sub中,在這裏你調用一個名爲db的本地notesdatabase對象,而沒有實際初始化它。

set maildoc = New NotesDocument(db) 

將失敗。 要麼全局聲明數據庫並將其設置爲您在該子數據庫中的初始化或模糊化並再次設置數據庫(最壞的情況,因爲您必須爲每個文檔執行此操作)

+0

聲明數據庫全球,它現在工作正常..謝謝很多 – user1912987