vbaoutlookmailitem

Displaying mailitem generates Runtime Error -2147467259


I loop through a MailItem collection to display the MailItem if the conversationID is the same as the request.

However, it seems, when the item searched is not on the ActiveSelection and the MailItem.Display function is called it produces the 'Runtime Error -2147467259'

Outlook can't do this because a dialog box is open. Please close it and try again.

Here is the code

'  email_link_Click()                                                                   '
'           -> Compares the ConversationID sent through to get the email                '
Sub email_link_Click()
    Dim searchFolder As Object

    Set olNs = Application.GetNamespace("MAPI")
    Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
    Set searchFolder = olFldr

    If Not Me.email_folder.Caption = "Inbox" Then
       Set searchFolder = olFldr.Folders(Me.email_folder.Caption)
    End If

    searchFolder.Items.Sort "[Subject]", False

    For Each emailvar In searchFolder.Items
        If emailvar.ConversationID = Me.conversationID_label.Caption Then
            FilingPrint ("Found email - Opening..")
            emailvar.Display '<- Error is created from here
            Exit Sub
        End If
    Next emailvar

    Set searchFolder = Nothing
End Sub

Is this because it cannot view two email's at once?


Solution

  • So in the end the issue was that effectively I had 2 instances of the view opened. Instead of spending too much time on it, I created a user-form that looks like an email view and pulled the details from a parsed MailItem object.