Avatar of jdc1944
jdc1944Flag for United Kingdom of Great Britain and Northern Ireland asked on

Sending emails from Access - Error 287

I'm trying to send an email from Access using Outlook.  I have several macros that send emails for different purposes, most using the docmd.sendobject method.  This works fine althought a security message does pop up in Outlook askingthe user to confirm the action, which is not a problem.

I then have another macro that is used to send an email with a word document as an attachement.  All was fine when we were using XP and 2003 but having upgraded to Win 7 and Office 2010 this no longer works.  I have tried several different methods of sending this email but the jist of it is ...

Dim oLook As Object
Dim oMail As Object
Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.CreateItem(0)

With oMail
   .To = test@test.com
   .Body ="Hello World"
   .Subject = "hello"
   .Attachments.Add ("attachment.doc")
   .Send
End With

Open in new window


All the different codes I have tried vary arround the use of creating an Outlook object.  I can't use the SendObject method because it does not support attachments.

The error message that I get is...
Run-time error '287':
Application-defined or object-defined error.

I have done a lot of research on the net trying to find a solution which I have not been able to find.

One thing that does keep coming up is security within Outlook not allowing Access to send emails.  Outlook doesn't even come up with the message asking the user to confirm the issue.

Has anyone else come up against this and know of a solution, whether in Access or Outlook?

TIA.
Microsoft AccessOutlook

Avatar of undefined
Last Comment
jdc1944

8/22/2022 - Mon
Rey Obrero (Capricorn1)

change this

  .Attachments.Add ("attachment.doc")

to include the full path to the document

  .Attachments.Add ("c:\foldername\attachment.doc")
ASKER CERTIFIED SOLUTION
Joe Howard

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
regmigrant

This is generated either when security disallows all programmatic access or user says 'no' to the request.

Have you tried to either disable outlook security or sign your project/MDB with a certificate so it is trusted
ASKER
jdc1944

@MacroShadow
I've just used a CDO example and got it to work, thanks.  The only issue with that is the sent email does not appear in the sent items.  We kind of need this for an audit trail.  Do you know if this is possible at all?

@regmigrant
Thanks, all the settings are locked but I will get IT to change them for me and see if that gets my old code working in case the CDO method doesn't allow messages to be shown in the sent items of outlook.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Joe Howard

When you sent an email using cdo it won't show up in Outlook's sent items since you are interacting directly with the mail server, the sent items are a mail client function, in your case Outlook's.
regmigrant

You could cc the local user and set a category as an audit trail using CDO - this might be easier than the security/signing option
ASKER
jdc1944

Thanks, now set everything up using CDO and using the CC opetion as an audit trail.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.