Solved

Send e-mail with attachments from Access

Posted on 2013-11-13
5
778 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 58
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 58

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Changing a few Outlook Options can help keep you organized!
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

690 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