Create a button in a form to email a report

  • Follow


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!

0
Reply Utf 3/18/2010 7:43:01 PM

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

"Amelia" <Amelia@discussions.microsoft.com> wrote in message 
news:365185D4-B942-4C88-A3BD-97E96B7949C2@microsoft.com...
> 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!
> 
0
Reply Mark 3/19/2010 8:32:02 PM



"Mark Andrews" wrote:

> 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
> 
> "Amelia" <Amelia@discussions.microsoft.com> wrote in message 
> news:365185D4-B942-4C88-A3BD-97E96B7949C2@microsoft.com...
> > 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!
> > 
> .
> 
0
Reply Utf 3/21/2010 3:13:01 AM

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

"Mark Andrews" wrote:

> 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
> 
> "Amelia" <Amelia@discussions.microsoft.com> wrote in message 
> news:365185D4-B942-4C88-A3BD-97E96B7949C2@microsoft.com...
> > 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!
> > 
> .
> 
0
Reply Utf 3/21/2010 3:25:01 AM

3 Replies
477 Views

(page loaded in 0.085 seconds)

Similiar Articles:
















7/24/2012 3:25:40 PM


Reply: