You'll find the code to create the pdf here:
http://www.lebans.com/reporttopdf.htm
You likely should get the above sample working on your computer before you
attempt to move and copy that above code into your own application. (So get
his sample working first). Do note the above sample also requires that you
place the appropriate DLL files in the same folder as your application.
You will have to use outlook automation.
So the whole approach here is that you're going to create a PDF a file that
is SAVED to disk. You then created the e-mail, and then set that pdf file as
an attachment.
The following code shows you how to start an outlook session, and then
attach a file of your choice to the e-mail.
So, *after* you create the pdf file, YOU then simply start a outlook
session, and attach the file you made using the pdf library.
eg:
dim strDocName as string
' send to user via email
'Dim ol As Outlook.Application
Dim ol As Object ' Late binding
'Dim ns As NameSpace
Dim ns As Object ' Late bind
'Dim newmessage As MailItem
Dim newmessage As Object ' Late bind
Dim mymessage As String
'Dim objOutlookAttach As Outlook.Attachment
'Dim objOutlookAttach As Object
strDocname = "c:\mydata\Report.pdf"
Set ol = GetObject(, "Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
ns.Logon
Set newmessage = ol.CreateItem(0) ' 0 = olMainItem
With newmessage
.Recipients.Add strEmailTo
.Subject = strSubject
.Body = strMsgText
'Set objOutlookAttach = .Attachments.Add(stDocName)
.Attachments.Add (strDocName)
.Display
' .Send
End With
I would consider to cobbile together your own "sendReprot" replacement code
combines both operations into one..
You could take the above code, and expand it with stephans pdf creater. You
get:
Public Sub EmailReport(strReportName As String, _
strSubject As String, _
strMsgText As String, _
strDocName As String, _
strEmailTo As String)
' sends the active report out....
' send to user via email
Dim MyReport As Report
Dim ol As Object ' Late binding 10/03/2001 -
Ak
Dim ns As Object ' Late bind
Dim newmessage As Object ' Late bind
Dim mymessage As String
'DoCmd.OutputTo acReport, strReportName, acFormatRTF, strDocName, False
Call ConvertReportToPDF(strReportName, , strDocName, False, False)
DoCmd.Close acReport, strReportName
On Error GoTo CreateOutLookApp
Set ol = GetObject(, "Outlook.Application")
On Error Resume Next
Set ns = ol.GetNamespace("MAPI")
ns.Logon
Set newmessage = ol.CreateItem(0) ' 0 = olMainItem
With newmessage
.Recipients.Add strEmailTo
.Subject = strSubject
.Body = strMsgText
.Attachments.Add (strDocName)
.Display
' .Send
End With
Exit Sub
CreateOutLookApp:
Set ol = CreateObject("Outlook.application")
Resume Next
End Sub
....