这就是我是如何用SendObject来做的,它把报告作为区域工作组并放在电子邮件的正文中。
Private Sub btnEmail_Click()
Dim IDnumber As Integer
Dim Message As String
Dim EmailTo As String
Dim FileName As String
Get the current record s ID Number
IDnumber = Me![ID]
set file name and path
FileName = Environ("USERPROFILE") & "My Documents emp.html"
set email address
EmailTo = "someone@domain.com"
get form to open a new record
DoCmd.GoToRecord , , acNewRec
generate report for the current record entered
DoCmd.OpenReport "ReportName", acPreview, , "[ID]=" & IDnumber, acHidden
create HTML file for the report
DoCmd.OutputTo acOutputReport, "ReportName", acFormatHTML, FileName
open file
Open FileName For Input As #1
read the file into a string
Message = Input(LOF(1) - 1, 1)
close the file
Close 1
generate email
DoCmd.SendObject acSendReport, "ReportName", acFormatRTF, EmailTo, , , "Subject", Message
close the report
DoCmd.Close acReport, "ReportName"
suppress errors if file is not there
On Error Resume Next
remove file
Kill FileName
End Sub