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
End With
'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
With olMail
.Attachment.Add (rstAttachments!EMailAttachment)
End With
End If
.MoveNext
Loop
End With
End If
With olMail
.Save
.Send
End With
Set olMail = Nothing
Set olApp = Nothing
MsgBox "Mail Sent!", vbOKOnly, "Mail Sent"
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
End With
'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
With olMail
.Attachment.Add (rstAttachments!EMailAttachment)
End With
End If
.MoveNext
Loop
End With
End If
With olMail
.Save
.Send
End With
Set olMail = Nothing
Set olApp = Nothing
MsgBox "Mail Sent!", vbOKOnly, "Mail Sent"
However the code under "Add Attachments" does not work. I get an error in line ".Attachment (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