Results 1 to 4 of 4
  1. #1
    kiwikiki718 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Posts
    11

    Send email with attachment


    I have a database which contains the following table and fields :QryEmail with fields; emailadress,subject,Attachment. the attachment field contains the path of the pdf that I would like to attach to each person when sending the email. my issue is that I am unsure how to insert the correct coding to add the attachment to the email. Please help.

  2. #2
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,361
    Are you using Automation? AFAIK, then the Outlook email object supports the attachment property, which can be a valid file path. Such as

    Code:
    With oEmail
      .To = Me.txtEmail
      .Subject = Me.txtSubject
      .Attachment = Me.txtAttachPath
    End With
    The red bold stuff is made up since not much info was revealed. You might want to employ validation; i.e., ensure the necessary information is available from your form.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    kiwikiki718 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2017
    Posts
    11
    Here is the coding that I am using: I receive a error message stating "operation failed".

    Dim Answer As VbMsgBoxResult
    Answer = MsgBox("Are you Sure you want to Send Emails?", vbYesNo, "Send Emails")
    If Answer = vbYes Then


    Dim olLook As Object
    Dim olNewEmail As Object
    Dim strSql As String
    Dim db As DAO.Database
    Dim rst As DAO.Recordset



    Set db = CurrentDb

    strSql = "SELECT * from qryEmail"

    Set rst = db.OpenRecordset(strSql, dbOpenDynaset)

    Do While Not rst.EOF


    Set olLook = CreateObject("Outlook.Application")
    Set olNewEmail = olLook.CreateItem(0)
    Set olNewEmail.SendUsingAccount = Outlook.Session.Accounts.Item(2)
    Set myattachments = olNewEmail.Attachments




    With olNewEmail 'Attach template
    .To = rst.Fields("[EMailAddress]")
    .SUBJECT = rst.Fields("[SUBJECT]")
    .HTMLBody = "<font size=5 pt><font color=red><b><u>PLEASE READ THE ENTIRE ATTACHED FILE.</u></b></font>"
    myattachments.Add = rst.Fields("ATTACH")
    .SendUsingAccount = olNewEmail.SendUsingAccount

    .Display
    End With

    rst.MoveNext
    Loop

    End If
    End Sub

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,361
    might be cross posted in this forum
    https://www.accessforums.net/showthread.php?t=65462

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Send attachment as email attachment.
    By JulieAHop in forum Programming
    Replies: 1
    Last Post: 03-10-2017, 10:25 AM
  2. Send email with PDF attachment
    By Rzadziu in forum Reports
    Replies: 8
    Last Post: 10-14-2016, 07:08 AM
  3. Send email with Attachment
    By scoe in forum Programming
    Replies: 3
    Last Post: 09-23-2014, 03:02 AM
  4. How to send email without attachment
    By behnam in forum Programming
    Replies: 3
    Last Post: 07-30-2014, 08:24 AM
  5. Beginner trying to send email with attachment
    By ahm in forum Programming
    Replies: 2
    Last Post: 03-24-2009, 08:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums