?
Solved

Acc2003 VBA Code Returns Error 287 when run in Acc2007

Posted on 2009-02-10
3
Medium Priority
?
872 Views
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
etc......
End Sub

Open in new window

0
Comment
Question by:Biggles1
3 Comments
 
LVL 28

Accepted Solution

by:
TextReport earned 2000 total points
ID: 23599615
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
0
 

Author Closing Comment

by:Biggles1
ID: 31544957
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.

Regards,

Biggles1
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

862 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