{"id":1095,"date":"2016-01-07T18:06:09","date_gmt":"2016-01-07T23:06:09","guid":{"rendered":"http:\/\/regina-whipp.com\/blog\/?p=1095"},"modified":"2016-07-04T16:29:53","modified_gmt":"2016-07-04T20:29:53","slug":"email","status":"publish","type":"post","link":"https:\/\/regina-whipp.com\/blog\/?p=1095","title":{"rendered":"eMailing specific Reports to specific Recipients&#8230;"},"content":{"rendered":"<p><strong>Question<\/strong>: Can anyone tell me how to eMail a report with content based data based on the individual?<\/p>\n<p><strong>Answer<\/strong>:<br \/>\nCreate a Module, name it anything you like except the name of the Function.<\/p>\n<p>At the top of your Module under\u2026<\/p>\n<p>Option Compare Database<br \/>\nOption Explicit<\/p>\n<p>\u2026place<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nPublic olApp As Object\r\nPublic olNameSpace As Object\r\nPublic objRecipients As Object\r\nPublic objNewMail As Object 'Outlook.MailItem\r\n<\/pre>\n<p>Then, we need something to initialize Outlook, so, copy\/paste the below into the same Module\u2026<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nFunction InitializeOutlook() As Boolean\r\n' This function is used to initialize the global Application and\r\n' NameSpace variables.\r\n    \r\n    On Error GoTo Init_Err\r\n    Set olApp = CreateObject(&quot;Outlook.Application&quot;, &quot;LocalHost&quot;)  ' Application object\r\n    Set olNameSpace = olApp.GetNamespace(&quot;MAPI&quot;)  ' Namespace object\r\n    Set objNewMail = olApp.CreateItem(0)\r\n    InitializeOutlook = True\r\nInit_Bye:\r\n    \r\n    Exit Function\r\nInit_Err:\r\n    InitializeOutlook = False\r\n    Resume Init_Bye\r\n    \r\nEnd Function\r\n<\/pre>\n<p>And now we can copy\/paste the Function into the same Module\u2026<br \/>\n<em>Note: After you have copied it you will need to change the Paths, Query, Report and Field Names to match your own.<\/em><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nFunction streMailOverdue() As String\r\nOn Error GoTo Error_Proc\r\n\u2018From: http:\/\/regina-whipp.com\/blog\/ \r\n    \r\n    DoCmd.Hourglass True\r\n    \r\n    'Set global Application and NameSpace object variables, if necessary.\r\n    If olApp Is Nothing Then\r\n        If InitializeOutlook = False Then\r\n            MsgBox &quot;Unable to initialize Microsoft Outlook!&quot;\r\n        End If\r\n    End If\r\n    \r\n    'Create new MailItem object.\r\n    Set objNewMail = olApp.CreateItem(0)\r\n    \r\n    Dim strTo As String\r\n    Dim strSQL As String\r\n    Dim rs As Recordset\r\n    Dim strSubject As String\r\n    Dim strBody As String\r\n    Dim strAttachment As String\r\n    \r\n    'Get the eMails for those who are to receive a Report\r\n    strSQL = &quot;SELECT apAssociateID, apeMailAddress &quot; &amp; _\r\n                &quot;FROM qryeMailAddresses&quot;\r\n\r\n    Set rs = CurrentDb.OpenRecordset(strSQL)\r\n    \r\n    'Save Report outside Access\r\n    With rs\r\n        .MoveFirst\r\n            Do While Not .EOF\r\n                DoCmd.OutputTo acOutputReport, &quot;rpteMailReport&quot;, acFormatPDF, &quot;\\\\SERVERNAME\\data\\eMailReports\\&quot; &amp; !apAssociateID &amp; &quot;-ToDoListFor_&quot; &amp; Format(Date, &quot;mm.dd.yyyy&quot;) &amp; &quot;.pdf&quot;\r\n                strAttachment = &quot;\\\\SERVERNAME\\data\\eMailReports\\&quot; &amp; !apAssociateID &amp; &quot;-ToDoListFor_&quot; &amp; Format(Date, &quot;mm.dd.yyyy&quot;) &amp; &quot;.pdf&quot;\r\n            'Send eMail and Report\r\n            Set objNewMail = olApp.CreateItem(0)\r\n            With objNewMail\r\n                .To = rs.Fields(&quot;apeMailAddress&quot;)\r\n                .Subject = &quot;To Do List Items Overdue!&quot;\r\n                .Body = &quot;See attachment...&quot;\r\n                    If strAttachment &lt;&gt; &quot;&quot; Then\r\n                        .Attachments.Add strAttachment\r\n                    End If\r\n                .Send\r\n            End With\r\n        .MoveNext\r\n        Loop\r\n            'Delete the Reports\r\n            If Dir(&quot;\\\\SERVERNAME\\data\\eMailReports\\*.pdf&quot;) &lt;&gt; &quot;&quot; Then\r\n                Kill &quot;\\\\SERVERNAME\\data\\eMailReports\\*.pdf&quot;\r\n            End If\r\n        End With\r\n        \r\n        rs.Close\r\n        Set rs = Nothing\r\n    \r\nExit_Proc:\r\n    DoCmd.Hourglass False\r\n    Exit Function\r\nError_Proc:\r\n    Select Case Err.Number\r\n        Case 287:\r\n          'On Error Resume Next\r\n          Resume Exit_Proc 'ignore the error'\r\n        Case Else:\r\n          MsgBox &quot;Error encountered streMailOverdue: &quot; &amp; Err.Description\r\n          Resume Exit_Proc 'display a message then exit'\r\n    End Select\r\n\r\nEnd Function\r\n<\/pre>\n<p>Now, on your Form in the <strong>Event Procedure<\/strong> of your <strong>Command Button<\/strong> place&#8230;<\/p>\n<p><strong>Call eMailOverdue<\/strong><\/p>\n<p>All done!<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1095\" class=\"pvc_stats all  \" data-element-id=\"1095\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/regina-whipp.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Question: Can anyone tell me how to eMail a report with content based data based on the individual?<\/p>\n<p>Answer: Create a Module, name it anything you like except the name of the Function.<\/p>\n<p>At the top of your Module under\u2026<\/p>\n<p>Option Compare Database Option Explicit<\/p>\n<p>\u2026place<\/p>\n<p> Public olApp As Object Public olNameSpace As Object Public [&#8230;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1095\" class=\"pvc_stats all  \" data-element-id=\"1095\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/regina-whipp.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[64,76,81,30,21],"class_list":["post-1095","post","type-post","status-publish","format-standard","hentry","category-access-tips","tag-access-tips","tag-email","tag-outlook","tag-reports","tag-vba","odd"],"_links":{"self":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1095"}],"version-history":[{"count":6,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1095\/revisions"}],"predecessor-version":[{"id":1101,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1095\/revisions\/1101"}],"wp:attachment":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}