Exporting to .pdf file in Office 2003

  • Thread starter Thread starter RSteph
  • Start date Start date
R

RSteph

Is it possible to export a report from Access to a .pdf file in office 2003.
I've got a report setup, and I attach it to an e-mail to send out, in office
2007 I can do it using the following command:

DoCmd.OutputTo acOutputReport, docname, acFormatPDF, "C:\Report.pdf"

Then run a command to attach it in outlook to an e-mail. Can I do this (by
default) with Access2003? Or would I need to get a driver/library file to get
this to work? Or is it simply not possible in 2003?

Any help would be greatly appreciated. Thank you.
 
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

....
 
Back
Top