I need to attach files to an email, using Outlook as the email client.
The number of attachments is random.
In Access I write the full path of the file to be attached to the field "EMailAttachment" in table "tblTempSendEMailAttachments" at run time.
I have the following code:
The code to create the email works. However when the code: Set objOutlookAttach = .Attachments.Add(rstAttachments!EMailAttachment) runs I get an error 325 -Operation is not supported for this type of object.
What am I doing wrong, and how do I correct it?
Many thanks in advance
The number of attachments is random.
In Access I write the full path of the file to be attached to the field "EMailAttachment" in table "tblTempSendEMailAttachments" at run time.
I have the following code:
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 rstAttachments 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
[COLOR=red]Set objOutlookAttach = .Attachments.Add(rstAttachments!EMailAttachment)[/color]
End With
End If
.MoveNext
Loop
End With
End If
With olMail
.Save
.Send
End With
Set olMail = Nothing
Set objOutlookAttach = Nothing
Set olApp = Nothing
MsgBox "Mail Sent!", vbOKOnly, "Mail Sent"
The code to create the email works. However when the code: Set objOutlookAttach = .Attachments.Add(rstAttachments!EMailAttachment) runs I get an error 325 -Operation is not supported for this type of object.
What am I doing wrong, and how do I correct it?
Many thanks in advance