Link to home
Start Free TrialLog in
Avatar of LJShepherd
LJShepherd

asked on

Send e-mail with attachments from Access

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
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

You don't want the .Send

You also may need to do:

.Visible = True

so Outlook Displays.

Jim.
Avatar of LJShepherd
LJShepherd

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Thanks Jim, it worked perfectly.

Much appreciated.

Les