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
    objMail.Send
    Set objOutlook = Nothing
     
    Tim, Apr 9, 2010
    #1
    1. Advertisements

  2. Take a look at

    http://www.devhut.net/index.php?lang=en&pid=0000000013#OutlookAuto

    For a full Outlook automation function example which you can either simply
    use or use to fix your code with.
    --
    Hope this helps,

    Daniel Pineault
    http://www.cardaconsultants.com/
    For Access Tips and Examples: http://www.devhut.net
    Please rate this post using the vote buttons if it was helpful.



    "Tim" wrote:

    > 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
    > objMail.Send
    > Set objOutlook = Nothing
    >
    >
     
    Daniel Pineault, Apr 10, 2010
    #2
    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
    Err_Handler:
    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,



    "Daniel Pineault" wrote:

    > Take a look at
    >
    > http://www.devhut.net/index.php?lang=en&pid=0000000013#OutlookAuto
    >
    > For a full Outlook automation function example which you can either simply
    > use or use to fix your code with.
    > --
    > Hope this helps,
    >
    > Daniel Pineault
    > http://www.cardaconsultants.com/
    > For Access Tips and Examples: http://www.devhut.net
    > Please rate this post using the vote buttons if it was helpful.
    >
    >
    >
    > "Tim" wrote:
    >
    > > 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
    > > objMail.Send
    > > Set objOutlook = Nothing
    > >
    > >
     
    Tim, Apr 12, 2010
    #3
  4. Tim

    Jill Bolig Guest

    Did you find an answer?

    Daniel,

    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

    > On Friday, April 09, 2010 10:51 AM Tim wrote:


    > My codes generate the error 287 at the objMail.Send. I think the path is
    > wrong, but I do not 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
    > objMail.Send
    > Set objOutlook = Nothing



    >> On Saturday, April 10, 2010 10:38 AM Daniel Pineault wrote:


    >> Take a look at
    >>
    >> http://www.devhut.net/index.php?lang=en&pid=0000000013#OutlookAuto
    >>
    >> For a full Outlook automation function example which you can either simply
    >> use or use to fix your code with.
    >> --
    >> Hope this helps,
    >>
    >> Daniel Pineault
    >> http://www.cardaconsultants.com/
    >> For Access Tips and Examples: http://www.devhut.net
    >> Please rate this post using the vote buttons if it was helpful.
    >>
    >>
    >>
    >> "Tim" wrote:



    >>> On Monday, April 12, 2010 2:55 PM Tim wrote:


    >>> 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
    >>> Err_Handler:
    >>> MsgBox Err.Description & " " & Err.Number
    >>>
    >>> Where it describles the error message 287.
    >>>
    >>> Do you think it is because of the configuration of the exchange
    >>> server/account? Thank you,
    >>>
    >>>
    >>>
    >>> "Daniel Pineault" wrote:



    >>> Submitted via EggHeadCafe - Software Developer Portal of Choice
    >>> Mocking WCF Services Using Moq
    >>> http://www.eggheadcafe.com/tutorial...61d435d81/mocking-wcf-services-using-moq.aspx
     
    Jill Bolig, Sep 30, 2010
    #4
  5. Tim

    braidedmane

    Joined:
    Aug 9, 2012
    Messages:
    1
    Likes Received:
    0
    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
    #5
  6. Tim

    sachinsinghsks

    Joined:
    Feb 14, 2014
    Messages:
    1
    Likes Received:
    0
    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
    #6
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    3
    Views:
    256
  2. Anne

    Error Message "User-defined type not defined"

    Anne, Apr 7, 2004, in forum: Microsoft Access VBA Modules
    Replies:
    8
    Views:
    333
    Ted Allen
    Apr 7, 2004
  3. Jim

    Access 2007 runtime error 287 application-defined...

    Jim, Dec 20, 2008, in forum: Microsoft Access VBA Modules
    Replies:
    7
    Views:
    2,055
    Gina Whipp
    Dec 30, 2008
  4. Adam USAF

    Using Automation to send Microsoft Outlook Message - error 287

    Adam USAF, Jan 15, 2009, in forum: Microsoft Access VBA Modules
    Replies:
    4
    Views:
    9,448
    AmmoAndy
    Nov 5, 2010
  5. Opal

    Application defined or object defined error

    Opal, Jun 18, 2009, in forum: Microsoft Access VBA Modules
    Replies:
    3
    Views:
    267
Loading...

Share This Page