Emailing PDF Report

dazstarr

Registered User.
Local time
Today, 12:50
Joined
Mar 19, 2007
Messages
132
Hi

Can someone please help me? I am not a VB programmer - i just know the very basics.

I am using Stephen Lebans PDF code to create a report which converts into PDF format.

Currently the user clicks on a button to preview the report - i have added the following line (in blue) underneath the open report function.

DoCmd.OpenReport stDocName, acPreview, , "[CPID]=" & Me!CPID
Call ConvertReportToPDF(stDocName, , "C:\Documents and Settings\All Users\Desktop\ContactMessage.pdf", False, False)

This works fine - I get a preview of the report onscreen in snapshot format and the pdf saves to the desktop.

What I would like to do is add some code which will close the snapshot view and open the PDF so users can email the document via FILE - SEND.

Ideally I would prefer an outlook window to come up when they press the button with the PDF attached.

Can someone help me with this please?

Many Thanks in advance
Daz
 
This isn't a 100% solution but shows you how to do it.



Code:
Dim OutlookMessage As Object
Set OutlookMessage = CreateObject("Outlook.application").createitem(0)

'Repeat the following line for every file you want to attach to the Message
OutlookMessage.attachments.Add "C:\Reports\" & "HIPRI.rtf"
OutlookMessage.Subject = Format(Date, "DDDD, MMMM dd yyyy") ' Optional line
OutlookMessage.body = "Here's your file".

'You can also do

OutlookMessage.to = "someaddress@somewhere.com

'Adding a recipient or trying to send the email will call the "Outlook watchdog on you"

OutlookMessage.Send
 
Thanks so much for that - it works great. I would like to tweak one more aspect if possible. Rather than hard coding an email address - would it be possible to bring up the new message window from outlook so a user can select the recipient?

Many Thanks
Daz
 
Many people don't like it, and you can use your own form, but this is the easiest and fastest way.

Code:
EmailAddress = InputBox("Please enter the email address you would like to send the email to", "Enter Email Address")
 
Last edited:
Thanks for your reply Mutdogus!

I will give it a try - the way mine works at the mo - it picks the name of the receipient from a field on my form. It's pretty cool actually as it resolves the name from the global address list on outlook without me telling it to!

However the plot has thickened - when I presented my new super cool database to management - she said can it send to multiple people too?

DOH!!! :mad::mad:

So I am looking into a outlook window popping up with the file attached so they can choose the reciepient themselves.

The saga continues..:mad:
 
Mine sends to multiple people.

I loop thru a table that I have all the email addresses that I want to send to and do a outlookmessage.to =

for each record.
 
I managed to sort it, I asked her is she will ever need to send to more than 2 people - she said no. So what I did was add an addtional combo box to choose another member of staff.

Then I added the following line in the code:

outlookmessage.cc - and then the field name which includes the secondary staff name.

It now CC's the person I add in there and works a treat!:)
 

Users who are viewing this thread

Back
Top Bottom