Sending Email using Outlook Error 287 (1 Viewer)

Catalina

Registered User.
Local time
Today, 15:17
Joined
Feb 9, 2005
Messages
462
Access/Outlook 2010

I used the code listed at the bottom to email a report as an attachment.
It used to work fine but now it gives me an error:

#287 Application-defined or Object-defined error

Caused by these lines:
Code:
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")

Any idea how to fix this?

Update: Outlook has to be opened.
CreateObject was not sufficient for this. When I added this to my code, it fixed the problem: Shell "Outlook.exe"

Not a nice solution, is there a way to get around it?

Thanks

Code:
    Dim objOutlook As Object
    Dim objOutlookMsg As Object
    Dim objOutlookRecip As Object
    Dim objOutlookAttach As Object

    Dim Currfile As String

    Currfile = "D:\Archive\Test.pdf"


    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")
    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    With objOutlookMsg
        ' Add the To recipient(s) to the message.
        Set objOutlookRecip = .Recipients.Add("myemail1@gmail.com")
        objOutlookRecip.Type = olTo
        ' Add the CC recipient(s) to the message.
        Set objOutlookRecip = .Recipients.Add("myemail2@gmail.com")
        objOutlookRecip.Type = olCC
        ' Set the Subject, Body, and Importance of the message.
        .Subject = "Test Report"
        .Body = "Here are the reports" & vbCrLf & vbCrLf
        .Importance = olImportanceHigh    'High importance

        ' Add attachments to the message.
        .Attachments.Add Currfile

        ' Resolve each Recipient's name.
        For Each objOutlookRecip In .Recipients
            objOutlookRecip.Resolve
            If Not objOutlookRecip.Resolve Then
                objOutlookMsg.Display
            End If
        Next
        .Send
    End With
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
 
Last edited:

sjlevine34

New member
Local time
Today, 15:17
Joined
May 14, 2014
Messages
5
The approach of shelling OUTLOOK.EXE also has the problem of creating additional instances of Outlook if outlook is already running when you invoke the command. At least this is true for Outlook 2010:banghead:
 

Users who are viewing this thread

Top Bottom