Acc2003 VBA Code Returns Error 287 when run in Acc2007

Posted on 2009-02-10
Last Modified: 2013-11-27
I have created code in Acc2003 that runs fine.  The code takes a string which is an email address and opens Outlook 2003 and inserts the email address in the To: Field.
When this code tries to send the email address to Outlook 2007 I get this error message:
Error 287 'Application-defined or Object-defined error'.  I know EXACTLY the line of code that generates this error. See code below.
I tried to run the code out of Acc2007 with Outlook 2007.  SAME result.  It makes no diference whether I use Acc2003 or Acc2007,  the problem comes when the destination is Outlook2007.
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)

On Error GoTo Err_SendMessage:

          Dim objOutlook As Outlook.Application

          Dim objOutlookMsg As Outlook.MailItem

          Dim objOutlookRecip As Outlook.Recipient

          Dim objOutlookAttach As Outlook.Attachment

          Dim dbs As Database


          Set dbs = CurrentDb

          ' 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(strEmailTo) THIS LINE CAUSES THE ERROR

                objOutlookRecip.Type = olTo


           End With


End Sub

Open in new window

Question by:Biggles1
    LVL 8

    Expert Comment

    LVL 28

    Accepted Solution

    Where is strEmailTo set and what is it's value?
    If this is a control on the form then you would normally name the textbox txt rather than str
    Cheers, Andrew

    Author Closing Comment

    Thanks for quick response.  strEmailTo is actually an email address (for example '') and it is generated in the Access database by VBA code which takes the contents of a text box (which contains an email address) and tries to send this to Outlook.  Again, if Outlook is 2003 everything works fine.  If Outlook is 2007 I get the error message.  See my code and the line which causes the error.



    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now