Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write macro to Print Access Report to PDF then E-mail

Status
Not open for further replies.

Bullsandbears123

Technical User
Feb 12, 2003
291
US
PLEASE HELP!
I am just starting to automate my database. I am using Access 2002 and outlook 2002

I do not know how to program a macro that would

1) open a report
2) Print that report to PDF
3) set the save to a particular folder
4) Close report
5) Send saved PDF file automatically to single e-mail address.
6) repeat every month on the 1st or 5th.

Can anybody give my some advice as to how the code will look?

 
I am working with Access 97, and it does not have PDF as an available format for outputting reports. But the following code outputs a report in HTML format and then creates an email in my outlook drafts folder with the report as an attachment.


Set olApp = New Outlook.Application

Set olMsg = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts).Items.Add(olMailItem)

'This sends the report
DoCmd.OutputTo acReport, "Summary Info Level 1", acFormatHTML, conExportPath & "Email Report.html"
olMsg.To = "Email Address"
olMsg.CC = "Email Address"
olMsg.Subject = "Email Subject"
olMsg.Body = "Text for Body of Message"
olMsg.Attachments.Add (conExportPath & "Email Report.html")
olMsg.Save
Set olMsg = Nothing



Hope this helps.
 
This works for me

DoCmd.SendObject acSendReport, <Your Report name>, acFormatXLS, <Email address>, , , _
<Subject>, &quot;Please find attached the monthly report for your information.&quot; & vbCrLf & vbCrLf & &quot; Kind Regards&quot; & vbCrLf & vbCrLf & &quot;<Your name>&quot;, 1

As long as you have outlook open this will do the job. however this is excel format. you can use acFormatRTF Im n ot sure about pdf though
If you change the 1 at the end of the code to 0 then the email will be sent automatically
if it is 0 then the outlook message window with your message and attachment will appear

hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top