<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Philip Wilmot &#187; Access</title>
	<atom:link href="http://philipwilmot.co.uk/blog/category/access/feed/" rel="self" type="application/rss+xml" />
	<link>http://philipwilmot.co.uk/blog</link>
	<description>the ever learning IT professional</description>
	<lastBuildDate>Wed, 12 Jan 2011 18:31:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Access 2007 &#8211; Email Report As Attachment</title>
		<link>http://philipwilmot.co.uk/blog/2010/02/access-2007-email-report-as-attachment/</link>
		<comments>http://philipwilmot.co.uk/blog/2010/02/access-2007-email-report-as-attachment/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 13:54:25 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Access]]></category>

		<guid isPermaLink="false">http://philipwilmot.co.uk/blog/?p=57</guid>
		<description><![CDATA[You have a Form which you have created, perhaps this Form is used for Ordering, you would then like to E-mail the order as a Report, outputted as PDF. You would also like the attachment (PDF Report) named based on your Order Number. First create your report and customise it to your needs. Back on [...]]]></description>
			<content:encoded><![CDATA[<p>You have a Form which you have created, perhaps this Form is used for Ordering, you would then like to E-mail the order as a Report, outputted as PDF. You would also like the attachment (PDF Report) named based on your Order Number.</p>
<p>First create your report and customise it to your needs.</p>
<p>Back on your Form create a Command Button and use the Command Button Wizard to setup the basic Sending concept. Select Report Operations, then Mail Report. Select your report and enter your desired Text. Finally give it a meaningful name. This will create an [Event Procedure] for the On Click Property. It will look a little like the following:<br />
<code><br />
Private Sub Command50_Click()<br />
On Error GoTo Err_Command50_Click<br />
Dim stDocName As String<br />
stDocName = "rpt_stock_order_po"<br />
DoCmd.SendObject acReport, stDocName<br />
Exit_Command50_Click:<br />
Exit Sub<br />
Err_Command50_Click:<br />
MsgBox Err.Description<br />
Resume Exit_Command50_Click<br />
End Sub<br />
</code></p>
<p>Modify the following line&#8230;</p>
<p><code>DoCmd.SendObject acReport, stDocName</code></p>
<p>&#8230;to look something more like</p>
<p><code>DoCmd.SendObject acReport, stDocName, acFormatPDF, "supplier@company.com", , , "Ink Order", "Please find enclosed our Ink Order", True</code></p>
<p>This will specifically output the Report as PDF (Office 2007 SP2 Required), automatically add the Email address, complete the Subject Line  and fill out the Body of the Email. Should you want it to automatically send it change the True to False.<br />
However you will notice the attachment is named whatever the Report is called or what is completed in the Report Caption property. If you have entered anything in the Report Caption property remove it now as we will automatically create this next. It will automatically be changed accordingly to a specific detail on your Report, such as a order number.</p>
<p>Open your Report and select an [Event Procedure] for the Report Load function.<br />
Add the following line:</p>
<p><code>Me.Caption = "Order " &amp; [your-order-number-field]</code></p>
<p>You will notice your Report title will change based upon your order number when opening the report. You will also notice that when trying to send your Report from your Form it still names the attachement to whatever your Report is called and not what the Caption is!<br />
This is because we need the Report to open up before so it can process the Caption change. If we go back to the send Report code and inbetween declaring <code>stDocName</code> and <code>DoCmd.SendObject</code> add the following to Open your report.</p>
<p><code>DoCmd.OpenReport stDocName, acPreview</code>.</p>
<p>Upon clicking on your Command Button, the Report will open with the correct title caption, and your E-mail client will have the correctly named attachment based on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://philipwilmot.co.uk/blog/2010/02/access-2007-email-report-as-attachment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

