Emailing an Attachment - Code

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
 
U

UpRider

SS, as an example, this works for me:
Note that strAttach is previously made equal to the full pathname of the
target document
elsewhere in the (not shown) code.
HTH, UpRider

With newMail
.Subject = "Your " & strMOalpha & " DBTC Newsletter"
.To = strSender
.BCC = strBCCList
If strAttach <> "NONE" Then
.Attachments.Add strAttach
End If
.Body = strBody
'.attachments.Add "c:\Path\to\the\next\file.txt" 'additional
attachments
'.Send
.Display
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top