I have the following code to send emails from Access:
However the code under "Add Attachments" does not work. I get an error in line "Set objOutlookAttach = .Attachments.Add(rstAttachments!EMailAttachment)"
I write the url of every file to be attached to the email as records in a table called "tblTempSendEMailAttachments".
I want to loop through the table as attach the files to the email
Thanks in advance
Code:
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim objOutlookAttach As Outlook.Attachment
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.BodyFormat = olFormatHTML
.To = Left(pubMessageRecipientsToAddress, Len(pubMessageRecipientsToAddress) - 1)
.CC = ""
.Subject = pubMessageSubject
.Body = pubMessageBody
'Add Attachments
Dim db As DAO.Database
Dim rstAttachements As DAO.Recordset
Set db = CurrentDb()
Set rstAttachments = db.OpenRecordset("Select EMailAttachment from tblTempSendEMailAttachments")
If rstAttachments.RecordCount > 0 Then
With rstAttachments
.MoveLast
.MoveFirst
Do Until .EOF
If DoesFileExist(rstAttachments!EMailAttachment) Then
Set objOutlookAttach = .Attachments.Add(rstAttachments!EMailAttachment)
End If
.MoveNext
Loop
End With
End If
.Save
.Send
End With
Set olMail = Nothing
Set objOutlookAttach = Nothing
Set olApp = Nothing
MsgBox "Mail Sent!", vbOKOnly, "Mail Sent"
I write the url of every file to be attached to the email as records in a table called "tblTempSendEMailAttachments".
I want to loop through the table as attach the files to the email
Thanks in advance