Mr. Southern
Registered User.
- Local time
- Today, 02:48
- Joined
- Aug 29, 2019
- Messages
- 90
Hello,
I have 5 reports that I want to send via outlook at the same time from a push of a button on an access form.
I have currently have:
After I compile and run it gets a runtime error '-2147024894(80070002)'.
If I debug it shows:
It does open outlook and inserts email, subject, and body but no attachments.
What am I missing?
I have 5 reports that I want to send via outlook at the same time from a push of a button on an access form.
I have currently have:
Code:
Option Compare Database
Function sndrpt()
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strAttach1 As String
Dim strAttach2 As String
Dim strAttach3 As String
Dim strAttach4 As String
Dim strAttach5 As String
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'Output Reports
DoCmd.OutputTo acOutputReport, "qry_SoilB", acFormatXLS, "F:\WH\Ft\Soil Report.xls", False
DoCmd.OutputTo acOutputReport, "qry_SoilM", acFormatXLS, "F:\WH\Ft\Soil Report.xls", False
DoCmd.OutputTo acOutputReport, "qry_SoilR", acFormatXLS, "F:\WH\Ft\Soil Report.xls", False
DoCmd.OutputTo acOutputReport, "qry_SoilS", acFormatXLS, "F:\WH\Ft\Soil Report.xls", False
DoCmd.OutputTo acOutputReport, "qry_SoilSt", acFormatXLS, "F:\WH\Ft\Soil Report.xls", False
'Set Attachments
strAttach1 = "F:\WH\Ft\Soil Report\qry_SoilB.xls"
strAttach2 = "F:\WH\Ft\Soil Report\qry_SoilM.xls"
strAttach3 = "F:\WH\Ft\Soil Report\qry_SoilR.xls"
strAttach4 = "F:\WH\Ft\Soil Report\qry_SoilS.xls"
strAttach5 = "F:\WH\Ft\Soil Report\qry_SoilSt.xls"
'Generate email
With objEmail
.To = "Test@Test.com"
.Subject = "Reports"
.Body = "Report for Current Day"
.Display
.Attachments.Add strAttach1
.Attachments.Add strAttach2
.Attachments.Add strAttach3
.Attachments.Add strAttach4
.Attachments.Add strAttach5
End With
'Remove attachments from drive
Kill strAttach1
Kill strAttach2
Kill strAttach3
Kill strAttach4
Kill strAttach5
End Function
After I compile and run it gets a runtime error '-2147024894(80070002)'.
If I debug it shows:
Code:
.Attachments.Add strAttach1
It does open outlook and inserts email, subject, and body but no attachments.
What am I missing?