使用 MS Access 中的 VBA 代码生成器,我能够编写打开 Outlook 的代码,并通过单击按钮向我发送电子邮件。我在添加附件时遇到问题。我发现的大多数代码都会将 MS 数据库外部的文件添加为附件,我想添加在我的数据库中创建的报告作为附件。
Private Sub EmailReport_Click()
Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
'Email the results of the report generated
Set oEmail = oApp.CreateItem(olMailItem)
oEmail.To = "[email protected]"
oEmail.Subject = "Training Roster"
oEmail.Body = "Roster Information"
With oEmail
.Send
MsgBox "Email Sent"
End With
我一直在研究类似的命令
oEmail.Attachments.Add Me.
..但是,我找不到添加报告的正确组合。
谢谢!!
如前所述,将报告导出到外部文件(例如 .pdf)中,以便附加到您的外发电子邮件中。请记住,报告是内部 Access 对象,不易采用电子邮件文件格式。和DoCmd.输出到,您可以动态创建带有日期标记的 pdf 并在相同位置作为为所有用户提供通用解决方案的数据库。
Private Sub EmailReport_Click()
Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
Dim fileName As string, todayDate As String
'Export report in same folder as db with date stamp
todayDate = Format(Date, "MMDDYYYY")
fileName = Application.CurrentProject.Path & "\ReportName_" & todayDate & ".pdf"
DoCmd.OutputTo acReport, "ReportName", acFormatPDF, fileName, False
'Email the results of the report generated
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
.Recipients.Add "[email protected]"
.Subject = "Training Roster"
.Body = "Roster Information"
.Attachments.Add fileName
.Send
End With
MsgBox "Email successfully sent!", vbInformation, "EMAIL STATUS"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)