Solved

Send e-mail with attachments from Access

Posted on 2013-11-13
5
724 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

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
You don't want the .Send

You also may need to do:

.Visible = True

so Outlook Displays.

Jim.
0
 

Author Comment

by:LJShepherd
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Jim, it worked perfectly.

Much appreciated.

Les
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Use email signature images to promote corporate certifications and industry awards.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now