Emailing multiple Access Reports as PDF attachments in one email

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
I'm trying to email three reports in the MS Access database as PDF attachments in one email. The report names are highlight in red below. I found this code and modified it to use for this situation but, I'm getting a "compile error - user-defined type not defined" error right on the first line "Dim objOutlook As Outlook.Application". I'm new to VBA and don't know how to fix this. Thanks for any help.


Private Sub email_cirr_lss_rpts_Click()

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strAttach1 As String
Dim strAttach2 As String
Dim strAttach3 As String

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

'Output Reports
Rem <!-- change "Reportx" to match the report names you wish to export. & _
IMPORTANT: Make sure the location you select to save your reports to exists, Access will & _
not create the folders for you. -->
DoCmd.OutputTo acOutputReport, "r_cirr_lss_call_Log_detail", acFormatPDF, "F:\CIRR_LSS Call Log\Reports", False
DoCmd.OutputTo acOutputReport, "r_cirr_lss_call_Log_summary", acFormatPDF, "F:\CIRR_LSS Call Log\Reports", False
DoCmd.OutputTo acOutputReport, "r_cirr_lss_call_Log_individual", acFormatPDF, "F:\CIRR_LSS Call Log\Reports", False


'Set Attachments
Rem <!-- make sure to correlate the attachments to each of the reports you wish to send -->
strAttach1 = "F:\CIRR_LSS Call Log\Reports\r_cirr_lss_call_Log_detail"
strAttach2 = "F:\CIRR_LSS Call Log\Reports\r_cirr_lss_call_Log_covid19_requests"
strAttach3 = "F:\CIRR_LSS Call Log\Reports\r_cirr_lss_call_Log_covid19_approved"


'Generate email
With objEmail
.To = "test@test.com;test2@test.com"
.Subject = "CIRR LSS Call Log Report"
.Body = "CIRR LSS Call Log Report"
.Display
.Attachments.Add strAttach1
.Attachments.Add strAttach2
.Attachments.Add strAttach3

End With

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Check your References in Tools/References in theVBA window. You need to set a reference to the Outlook object library.

You also need to give the reports filenames.? Why not define the strAttach early and use them for the output.?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top