Consulting

Results 1 to 7 of 7

Thread: Sending emails with attachments in Access

  1. #1

    Sending emails with attachments in Access

    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.

    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

  2. #2
    What is the datatype for the field rst.Fields("ATTACH")? Is is text?

    PS: You forgot to do the "clean up" after you were done with the recordset.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    Hi HitechCoach.Thanks for responding..yes the ATtach field is set to text. I have been trying to solve this issue going on 3 weeks now.

  4. #4
    I will be glad to help you get this working.

    I have not seen Outlook Automation code like what you have posted. I will have to test it.

    I will post back what I figure out from testing your code.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  5. #5
    Thanks so much for helping me. I will continue to work on this error in the meantime.

  6. #6
    I finally figured it out. Thanks everyone for your help.

  7. #7
    Quote Originally Posted by kiwikiki718 View Post
    I finally figured it out. Thanks everyone for your help.
    Great job figuring it out.

    Would you please pay it forward by posting your solution.

    Thank you.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

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
  •