访问女士发送带有报告作为附件的电子邮件 [英] Ms Access Send Email with Report as Attachment

查看:39
本文介绍了访问女士发送带有报告作为附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 MS Access 中使用 VBA 代码生成器,我已经能够编写代码来打开 Outlook 并通过单击按钮向我发送电子邮件.我在添加附件时遇到问题.我发现的大多数代码都将 MS 数据库之外的文件添加为附件,我想添加在我的数据库中创建的报告作为附件.

Using VBA code builder in MS Access, I have been able to write code that opens Outlook and send me an email with the click of a button. I am having problems with adding an attachment. Most code I have found adds files outside the MS Database as an attachment, I would like to add a report created in my database as an attachment.

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 = "myemailaddress@email.com"
oEmail.Subject = "Training Roster"
oEmail.Body = "Roster Information"

With oEmail
    .Send
    MsgBox "Email Sent"
End With

我一直在研究一个类似于

I have been looking into a command similar to

oEmail.Attachments.Add Me.

..但是,我找不到添加报告的正确组合.谢谢!!

..But, I cannot find the correct combination for adding my report. Thanks!!

推荐答案

如前所述,将您的报告导出到一个外部文件,例如 .pdf,以便附加到您的外发电子邮件中.请记住,报告是一个内部 Access 对象,不容易采用电子邮件的文件格式.使用 DoCmd.OutputTo,您可以在飞日期戳和相同位置适用于所有用户的通用解决方案.

As mentioned, export your report into an external file such as .pdf in order to attach to your outgoing email. Remember a report is an internal Access object and not readily in a file format for email. With DoCmd.OutputTo, you can dynamically create the pdf on the fly date-stamped and in same location as the database for a generalizeable solution for all your users.

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 "myemailaddress@email.com"
    .Subject = "Training Roster"
    .Body = "Roster Information"
    .Attachments.Add fileName
    .Send        
End With

MsgBox "Email successfully sent!", vbInformation, "EMAIL STATUS"

这篇关于访问女士发送带有报告作为附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆