G
Guest
I have the following code for sending an email including an attachment. It
keeps erroring out with a RunTime Error '13', type mismatch. It works fine
without the attachment code. Can anyone shed some light on how this line
should be written? I also have a filter that I'm using for the report but I
don't know how to enter that either.
Sub SendMessageGenerateReport(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim db As Database
Dim rsEmail As Recordset
Dim stTo, stFrom, stCC, stBCC, stSubject, stSal, stText As String
Dim stQuery As String
Dim stAttachPath As String
stSubject = "CA#: " & Forms![frmCorrectiveActionRMA]![CA#]
stText =
'Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
'Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
.To = Forms![frmCorrectiveActionRMA]![Employee].Column(5)
.BCC =
.Subject = stSubject
.Body = stText
.Attachments.Add "[Corrective Action Request Form]",
"SnapshotFormat(*.snp)"
.Importance = olImportanceNormal ' Normal Importance
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
keeps erroring out with a RunTime Error '13', type mismatch. It works fine
without the attachment code. Can anyone shed some light on how this line
should be written? I also have a filter that I'm using for the report but I
don't know how to enter that either.
Sub SendMessageGenerateReport(Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim db As Database
Dim rsEmail As Recordset
Dim stTo, stFrom, stCC, stBCC, stSubject, stSal, stText As String
Dim stQuery As String
Dim stAttachPath As String
stSubject = "CA#: " & Forms![frmCorrectiveActionRMA]![CA#]
stText =
'Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
'Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
.To = Forms![frmCorrectiveActionRMA]![Employee].Column(5)
.BCC =
.Subject = stSubject
.Body = stText
.Attachments.Add "[Corrective Action Request Form]",
"SnapshotFormat(*.snp)"
.Importance = olImportanceNormal ' Normal Importance
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub