• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 876
  • Last Modified:

Acc2003 VBA Code Returns Error 287 when run in Acc2007

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

1 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
Biggles1Author Commented:
Thanks for quick response.  strEmailTo is actually an email address (for example 'xxx@yyyy.com') 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.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now