Automated Email using Outlook

Eightball3

Registered User.
Local time
Today, 10:28
Joined
Jun 30, 2010
Messages
18
Well, this is driving me nuts!!
Just got upgraded to Office 2007. Our access application is erroring out when we try to send emails through access. I've been unable to find the problem so this is what I've done:

I found this code at http://support.microsoft.com/kb/161088

Option Compare Database
Option Explicit

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
'Dim objOutlook As Object
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' 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("Nancy Davolio")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Michael Suyama")
objOutlookRecip.Type = olCC

' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.send
End If
End With
Set objOutlook = Nothing
End Sub


I created a new database and inserted this code into a new module. I went into references and selected Microsoft Outlook 12.0 Object Library.

When I execute this code as described by the website, I get the exact same error message I'm getting in my application. Run-time error '287': "Application-defined or object-defined error"

Is it possible that some setting in Outlook is causing this? Anyone else having a similar issue? Running Office 2007...
 
Hello ghudson, thanks for your reply.

I placed your code into a new module in a new database. When I execute it I receive your "User aborted email" message, which is an error 287, the same error I'm receiving with the code I posted. Any ideas why this would be? Thanks!!
 

Users who are viewing this thread

Back
Top Bottom