Application-Defined or Object-Defined error 287

Discussion in 'Microsoft Access VBA Modules' started by Tim, Apr 9, 2010.

  1. Tim

    Tim Guest

    My codes generate the error 287 at the objMail.Send. I think the path is
    wrong, but I don't know why. If I use "On Error Resume Next" above the Send,
    then there is no error popping up, but there is no email sent, either. Please
    show me how to fix it. Thank you.
    strDocName = "frmStud"
    DoCmd.openfORM strDocName, acPreview, , "studId='" & glbStudId & "'"
    FileName = strDocName & ".pdf"
    DoCmd.OutputTo acOutputForm, strDocName, acFormatPDF,
    "C:\Temp\StudentForms\" & FileName, False
    'Using Outlook programming codes ....
    Dim objOutlook As Object
    Dim objMail As Outlook.MailItem

    Set objOutlook = CreateObject("Outlook.application")
    Set objMail = objOutlook.CreateItem(olMailItem)

    objMail.To = ""
    objMail.Subject = "test sending a form"

    objMail.Attachments.Add "C:\Temp\StudentForms\" & FileName

    'On Error Resume Next
    Set objOutlook = Nothing
    Tim, Apr 9, 2010
    1. Advertisements

  2. Daniel Pineault, Apr 10, 2010
    1. Advertisements

  3. Tim

    Tim Guest

    Hi Daniel, Thank you for the link, but for my program, it does NOT pop up the
    Outlook security warning. The execution reaches "objMail.Send" code and then
    jump down to these lines of codes
    MsgBox Err.Description & " " & Err.Number

    Where it describles the error message 287.

    Do you think it's because of the configuration of the exchange
    server/account? Thank you,
    Tim, Apr 12, 2010
  4. Tim

    Jill Bolig Guest


    Did you ever fix the problem you had with Access 2007? We are having the same problem trying to send emails through Access 2007. I have found many posts where other people were able to get the same code to work. We also think it is either an Access or an Outlook setting and we cannot figure out what it is. Have you resolved your issue?

    Jill Bolig, Sep 30, 2010
  5. Tim


    Aug 9, 2012
    Likes Received:
    In case anyone is frantically searching around for this answer (like I was) I finally found what MY issue was...

    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" 'Opens Outlook

    Bla bla code goes here

    Shell "taskkill /IM Outlook.exe" 'Closes Outlook again when code is finished (optional)
    braidedmane, Aug 9, 2012
  6. Tim


    Feb 14, 2014
    Likes Received:
    This "error 287" is because you have to open Microsoft outlook when you run macro. remember always open outlook when you are going to run macro because excel file uses outlook to send e-mails if outlook is not opened how do you think it will send e-mails? :) enjoy.
    sachinsinghsks, Feb 14, 2014
  7. Tim


    May 11, 2016
    Likes Received:
    I am aware that this is an old post, however ..... Take a look at my post on Stack Overflow.

    In summary, I found that the code run perfectly on "step through". The real difference between this and running the VBA sub on click event is the time scale. This lead me to finding a solution!
    Hope this helps!!
    LiamH, May 11, 2016
  8. Tim

    Ryan Miller

    Aug 23, 2016
    Likes Received:
    Assuming you are using the VBA from the Outlook application you want a handle on...
    Try replacing:
    Set objOutlook = CreateObject("Outlook.application")

    Set objOutlook= ThisOutlookSession
    Ryan Miller, Aug 23, 2016
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.