Solved

Send e-mail with attachments from Access

Posted on 2013-11-13
5
759 Views
Last Modified: 2013-11-13
Hi,

I want to send an e-mail from Access with attachments using a control button, but have the ability to edit the message before it goes.

I am using the code below to send, but cannot fathom out a way of adding code in to edit the message prior to sending.

Can you help please?

Thanks

Private Sub Command35_Click()
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
strAttach = "c:\Databases\pricer\" & Me.Ref & ".pdf"
With MailOutLook
    .BodyFormat = olFormatHTML
    .To = Me.e_mail
    ''.cc = ""
    ''.bcc = ""
    .Subject = "Quotation Ref" & Me.Ref
    .HTMLBody = "Please find attached your quotation"
    .Attachments.Add strAttach
    .Send
   
   
End With
 

End Sub
0
Comment
Question by:LJShepherd
  • 2
  • 2
5 Comments
 
LVL 57
ID: 39644275
You don't want the .Send

You also may need to do:

.Visible = True

so Outlook Displays.

Jim.
0
 

Author Comment

by:LJShepherd
ID: 39644290
Hi Jim,

I have added the .Visible, but I then get a RunTime error 438 message saying "Object doesn't support this property or method"

Thanks

Les
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 39644291
I just double checked, and to make it visible, you need to do:

            .Display

Which is a method of the mail object, not a property.

.Visible would be a property of Outlook itself and will probably work as well, but use the mail objects display method.  That will make the mail object visible for sure.

Jim.
0
 
LVL 6

Expert Comment

by:ButlerTechnology
ID: 39644295
Here's the code that I use for linking up with Outlook as a procedure:
Sub SendMailOutlook(Recipient, Subject, TextBody,  stAttachment)
  
  'Create an Outlook object
  Dim Outlook As New Outlook.Application
  Set Outlook = CreateObject("Outlook.Application")
  
  'Create e new message
  Dim Message As Outlook.MailItem
  Set Message = Outlook.CreateItem(olMailItem)

  With Message
    .Subject = Subject
    .HTMLBody = TextBody
    .To = Recipient
    .Attachments.Add (stAttachment)
    .Display
  End With
End Sub

Open in new window


With a little additional coding, the attachment could be made optional.

Tom
0
 

Author Closing Comment

by:LJShepherd
ID: 39644299
Thanks Jim, it worked perfectly.

Much appreciated.

Les
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
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 …

837 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