Create a button in a form to email a report

A

Amelia

I have a form set up in my DB that we fill out. I do have a button that will
print the report for this form set up, but now we would also like to have the
option to press a button and the report attaches itself to an email and we
can send it. I could set it up to just go to print preview and then we have
to go to the Acrobat tab, and select the "create and attach to email" but I
was hoping I could by-pass this step through code somehow. If anyone has any
ideas let me know!
 
M

Mark Andrews

As a guess (pass in reportname and whereclause), or perhaps you need to save
the pdf to disk and then construct the email, attach the file and send it.
It's definitely possible.

' open report in preview mode so we can pass in a where clause
DoCmd.OpenReport ReportName, acPreview, , WhereClause
DoCmd.SendObject acSendReport, ReportName, acFormatPDF
DoCmd.Close acReport, ReportName

Mark
 
J

J.Bennett

Mark Andrews said:
As a guess (pass in reportname and whereclause), or perhaps you need to save
the pdf to disk and then construct the email, attach the file and send it.
It's definitely possible.

' open report in preview mode so we can pass in a where clause
DoCmd.OpenReport ReportName, acPreview, , WhereClause
DoCmd.SendObject acSendReport, ReportName, acFormatPDF
DoCmd.Close acReport, ReportName

Mark


.
 
J

J.Bennett

I just tried to send a very lengthy response, but the post did not go
through.

I just accomplished this, but it was with much trial and error to get the
results I was after. My first suggestion is to add a button on your form and
see if the pdf report produced is limited to the record you want. I found
that the button to run the embedded macro would not work in my case as it
produced a report that contained every record int he database. Howerver, try
this method first. If it doesn't work, I'll share once again the code I used
to get to the end results to email the report as a pdf attachment.

In order to create the button I needed, I first had to create a button that
actually done something else, then edit the button to change it to the
SendObject command. I could not figure out how to use the wizard to create
the SendObject from the start. That's why the work around explained here.

On our form, create a button using the wizard to do a report option to "send
to a file". Once you complete the wizard, right click on the button, select
properties, then go to the "event" tab. Should have shown "embedded Macro".
Select the ... to the right of "embedded macro" to enter the macro. Now
change the command to "SendObject". Go to the bottom of the dialog box and
enter the object type as "Report", the report name, who to send it to (or
leave blank to prompt you), etc., etc.

Try this to see if it accomplishes what your after. If not, advise and I'll
once again try to share the longer process to filter the report down to one
record.

James Bennett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top