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

Time:10-14

I'm slowly attempting to get my head around COM classes as opposed to UI classes in Lotus Notes, and I have no idea why suddenly my function is throwing up an error when it doesn't use any UI classes to begin with.


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

The .GetFirstDocument line throws up the object variable not set error. Any insight into why would be appreciated.

CodePudding user response:

The GetFirstDocument line will throw object varaiable not set if NView is null. NView is null. Look at your first call to your Find_Document function. You have two calls there. I don't know why. They both look like this:

Set NDocument = Find_Document(NInboxView, findSubjectLike)

You are passing the view as NInboxView. Both times.

Now look above the first call. You haven't set NInboxView yet. You set a variable called NViewObj, instead. So for that first call, NInboxView is null. NViewObj, which you set using GetView, is presumably not null.

  • Related