使用access vba发送附件

时间:2017-04-06 08:55:09

标签: ms-access access-vba ms-access-2010

我正在使用以下代码。它的工作原理没有附加的代码行。但是一旦我添加了附件行,如果收到错误并且无法解决如何纠正它:

    Dim Email
Dim CC
Dim objOutlook    As Object
Dim objEmail      As Object
Dim db As Database
Dim rec As Recordset

'Export report in same folder as db with date stamp
todayDate = Format(Date, "MMDDYYYY")
fileName = Application.CurrentProject.Path & "\XXDispute_" & todayDate & ".pdf"
DoCmd.OutputTo acReport, "XXDispute", acFormatPDF, fileName, False

strItem = "http://schemas.microsoft.com/cdo/configuration/"
strFrom = "XX Disputes <asd@asd.com>"

Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = CreateObject("CDO.Message")

With objEmail

    .To = "asd@asd.com"
    .CC = ""
    .From = strFrom
    .Subject = "XXDispute Report: " & Now()
    .Textbody = "Your XX dispute has been reviewed and responded to:" & vbNewLine & vbNewLine
    .Attachments Add = fileName


With .Configuration.Fields
        .Item(strItem & "sendusing") = 2
        .Item(strItem & "smtpserver") = "mailhost"
        .Item(strItem & "smtpserverport") = 25
        .Update
    End With
    .Send
End With

这是导致问题的特定行:

    .Attachments Add = fileName

0 个答案:

没有答案