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