Lotus Notes 从 UI 更改为 COM 类 对象变量未设置错误

Lotus Notes changing from UI to COM classes object variable not set error

我正在慢慢尝试了解 COM 类 而不是 Lotus Notes 中的 UI 类,我不知道为什么我的函数突然抛出当它不使用任何 UI 类 开头时出错。


Public Sub Forward_Email(findSubjectLike As String, forwardToEmailAddresses As String)

    Dim NSession As Object
    Dim NMailDb As Object
    Dim NViewObj As Object
    Dim NInboxView As Object
    Dim NDocument As Object
    Dim NUIWorkspace As Object
    Dim NUIDocument As Object
    Dim NFwdUIDocument As Object
   
    
    Set NSession = CreateObject("Lotus.NotesSession")
    Call NSession.Initialize("")
    
    Set NMailDb = NSession.GetDatabase("", "", False)
    Set NViewObj = NMailDb.GetView("$Inbox")
    Set NDocument = Find_Document(NInboxView, findSubjectLike)
    
        For Each NViewObj In NMailDb.Views
        If NViewObj.IsFolder And NViewObj.Name = "($Inbox)" Then
            Set NInboxView = NViewObj
            Exit For
        End If
    Next
    
    Set NDocument = Find_Document(NInboxView, findSubjectLike)
    
   
End Sub

Private Function Find_Document(NView As Object, findSubjectLike As String) As Object

    Dim NThisDoc As Object
    Dim thisSubject As String
   
    Set Find_Document = Nothing
   
    Set NThisDoc = NView.GetFirstDocument
    While Not NThisDoc Is Nothing And Find_Document Is Nothing
        thisSubject = NThisDoc.GetItemValue("Subject")(0)
        If LCase(thisSubject) = LCase(findSubjectLike) Then Set Find_Document = NThisDoc
        Set NThisDoc = NView.GetNextDocument(NThisDoc)
    Wend

End Function

.GetFirstDocument 行抛出对象变量未设置错误。任何关于原因的见解都将不胜感激。

如果 NView 为空,则 GetFirstDocument 行将抛出未设置对象变量。 NView 为空。查看您对 Find_Document 函数的第一次调用。你那里有两个电话。我不知道为什么。它们看起来像这样:

Set NDocument = Find_Document(NInboxView, findSubjectLike)

您正在将视图作为 NInboxView 传递。两次。

现在看第一个电话。你还没有设置 NInboxView。相反,您设置了一个名为 NViewObj 的变量。因此对于第一次调用,NInboxView 为空。您使用 GetView 设置的 NViewObj 可能不为空。