使用访问命令按钮发送多个报告 [英] email multiple reports using access comand button

查看:64
本文介绍了使用访问命令按钮发送多个报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Access 2013中构建了一个简单的表单,其中包含一个电子邮件地址字段。

使用一个命令按钮我想在电子邮件中附加两份PDF报告。

这些报告是在Access中生成的。
  成功我只能用宏附加一个报告。
  报告必须是PDF,因为它们必须在发送前进行数字签名。  
我已经审查过很多关于上述问题的线索,但仍然没有得到它。  
如果我可以将两个报告和电子邮件合并为一个也没问题。  
  我是一个非常简单的程序的新手......但没有一个简单的解决方案。  
我们非常感谢您提供的任何帮助。

I have built a simple form in Access 2013 that among other things contains an email address field.
With one command button I would like to attach two PDF reports to the email.
These reports are generated within Access.
 With success I have been able to attach one report only with a macro.  The reports must be PDF, as they must be digitally signed prior to sending.  I have reviewed many threads regarding the above but still don’t get it.  If I could combine the two reports and email as one that would also be fine.   I am a novice with a very simple program… but without a simple solution.  Any help you can provide would be greatly appreciated.

推荐答案

您需要使用Office Automation来执行此操作。以下是一些示例代码,用于发送PDF作为附件:

You need to use Office Automation to do this. Following is some sample Code to send a PDF as an Attachment:

Public Function SendHTMLMessage()As Boolean

          Dim objOutlook作为Outlook.Application

          Dim objOutlookMsg As Outlook.MailItem

          Dim objOutlookRecip As Outlook.Recipient

          Dim objOutlookAttach作为Outlook.Attachment

          Dim strSendTo As String,strReportName As String

          Dim db As DAO.Database

          Dim rs As DAO.Recordset

          Dim dteMax As Date



On Error GoTo Err_SendHTMLMessage



          '创建Outlook会话。

         设置objOutlook = CreateObject(" Outlook.Application")



          '创建消息。

         设置objOutlookMsg = objOutlook.CreateItem(olMailItem)



  &NBSP; strSendTo ="< email address>"

  &NBSP; strBody ="< insert body of e-mail>"

  &NBSP; strFilename1 ="< insert path to file>" &NBSP;  

  &NBSP; strFilename2 ="< insert path to file>" &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;

Public Function SendHTMLMessage() As Boolean
          Dim objOutlook As Outlook.Application
          Dim objOutlookMsg As Outlook.MailItem
          Dim objOutlookRecip As Outlook.Recipient
          Dim objOutlookAttach As Outlook.Attachment
          Dim strSendTo As String, strReportName As String
          Dim db As DAO.Database
          Dim rs As DAO.Recordset
          Dim dteMax As Date

On Error GoTo Err_SendHTMLMessage

          ' Create the Outlook session.
          Set objOutlook = CreateObject("Outlook.Application")

          ' Create the message.
          Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    strSendTo = "<email address>"
    strBody = "<insert Body of e-mail>"
    strFilename1 = "<insert path to file>"    
    strFilename2 = "<insert path to file>"            

  &NBSP;  使用objOutlookMsg



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   .To = strSendTo



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;  '设置邮件的主题,正文和重要性。

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   .Subject ="< insert E-mail subject>"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   .Body ="" &安培; vbCrLf& vbCrLf

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   .Importance = olImportanceHigh 'High importance

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   .HTMLBody = strBody



$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;  '在邮件中添加附件。

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   .Attachments.Add(strFilename1)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   .Attachments.Add(strFilename2)

'

'  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; .SaveAs" 1",5

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;  。显示

'  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; 。发送



$
  &NBSP; &NBSP; &NBSP; &NBSP;结束与$
  &NBSP; &NBSP; &NBSP; &NBSP;设置objOutlook = Nothing

Exit_SendHTMLMessage:
$
SendHTMLMessage = True

  &NBSP;退出功能



Err_SendHTMLMessage:

如果Err.Number = 287则为
  &NBSP; MsgBox"您已选择不允许发送电子邮件。"

  &NBSP; booCancel = True

  &NBSP; GoTo Exit_SendHTMLMessage

Else

  &NBSP; MsgBox Err.Number& " " &安培; Err.Description

结束如果



结束功能

     With objOutlookMsg

             .To = strSendTo

             ' Set the Subject, Body, and Importance of the message.
             .Subject = "<insert E-mail subject>"
             .Body = "" & vbCrLf & vbCrLf
             .Importance = olImportanceHigh  'High importance
             .HTMLBody = strBody


             ' Add attachments to the message.
             .Attachments.Add(strFilename1)
             .Attachments.Add(strFilename2)
'
'                 .SaveAs "1", 5
                     .Display
'                     .Send


          End With
          Set objOutlook = Nothing
Exit_SendHTMLMessage:
SendHTMLMessage = True
    Exit Function

Err_SendHTMLMessage:
If Err.Number = 287 Then
    MsgBox "You have chosen to not allow e-mails to be sent."
    booCancel = True
    GoTo Exit_SendHTMLMessage
Else
    MsgBox Err.Number & " " & Err.Description
End If

End Function

这会将标识为strFilename1和2的文件添加为附件。

This will add the files identified as strFilename1 and 2 as attachments.


这篇关于使用访问命令按钮发送多个报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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