asked on
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim fileNameIncomeStatement As String, todayDateIncomeStatement As String
Dim fileNameSalesAnalysis As String, todayDateSalesAnalysis As String
Dim rptIncomeStatement As Object
Dim rptSalesAnalysis As Object
Dim FileArray As String
Dim AttachmentFiles, aFile
todayDateIncomeStatement = Format(Date, "MMDDYYYY")
todayDateSalesAnalysis = Format(Date, "MMDDYYYY")
'Email Reports...
fileNameIncomeStatement = Application.CurrentProject.Path & "\Income Statement_" & todayDateIncomeStatement & ".pdf"
DoCmd.OutputTo acReport, "Income Statement", acFormatPDF, fileNameIncomeStatement, , , , acExportQualityPrint
DoCmd.OpenReport "Income Statement", acViewPreview, , , acHidden
Reports![Income Statement].Visible = False
fileNameSalesAnalysis = Application.CurrentProject.Path & "\Sales Analysis_" & todayDateSalesAnalysis & ".pdf"
DoCmd.OutputTo acReport, "Sales Analysis", acFormatPDF, fileNameSalesAnalysis, , , , acExportQualityPrint
DoCmd.OpenReport "Sales Analysis", acViewPreview, , , acHidden
Reports![Sales Analysis].Visible = False
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.Recipients.Add Reports![Income Statement].txtEMail
.CC = "acct@somedomain.com"
.Subject = "Financial Statement for " & Reports![Income Statement].txtStartDate & " - " & Reports![Income Statement].txtEndDate
.Body = "Attached are both your Income Statement and Sales Analysis. If you have any questions please contact Susanne at someemail@somedomain.com or 123 456 7890."
.Attachments.Add fileNameSalesAnalysis
.Attachments.Add fileNameIncomeStatement
.Display
'.Send
End With
DoCmd.Close acReport, "Income Statement", acSaveNo
DoCmd.Close acReport, "Sales Analysis", acSaveNo
'End of email Reports