I have a database that is run by Task Scheduler at 6:15 every Friday morning. The autoexec macro in Access 2010 runs 2 queries and exports the data to 2 Excel files. Then the following code is run to email those 2 files to 4 users. I've used this method in several other databases without an issue. Now I get a prompt for each user to allow the email to be sent. I didn't get this in the other databases I used this method in.
Anybody know why I'm getting those prompts now? They're the same ones you get if you use the docmd.sendmail
Code:
Public Sub Masteremail()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOoutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim sfile As String
Dim filetocopy As String
Dim fs As Object
Set fs = CreateObject("scripting.filesystemobject")
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
'Add list of recipients here
objOutlookMsg.Recipients.Add ("someone1@somewhere.net")
objOutlookMsg.Recipients.Add ("someone2@somewhere.net")
objOutlookMsg.Recipients.Add ("someone3@somewhere.net")
objOutlookMsg.Recipients.Add ("someone4@somewhere.net")
With objOutlookMsg
.Subject = "Claim Audits Weekly Report"
.Body = ""
End With
sfile = "\\192.168.114.17\HVVHomeFolders\rmilhon\Development\Claims Audit Report\Claim_Audits_Facility.xlsx"
objOutlookMsg.Attachments.Add (sfile)
'sfile = "\\192.168.114.17\HVVHomeFolders\rmilhon\Development\Claims Audit Report\Claim_Audits_Facility" & "_" & Format(date(),"mmddyyyy") & ".xlsx"
Name sfile As "\\192.168.114.17\HVVHomeFolders\rmilhon\Development\Claims Audit Report\Claim_Audits_Facility" & "_" & Format(Date, "mmddyyyy") & ".xlsx"
sfile = "\\192.168.114.17\HVVHomeFolders\rmilhon\Development\Claims Audit Report\Claim_Audits_Professional.xlsx"
objOutlookMsg.Attachments.Add (sfile)
'sfile = "\\192.168.114.17\HVVHomeFolders\rmilhon\Development\Claims Audit Report\Claim_Audits_Professional" & "_" & Format(date(),"mmddyyyy") & ".xlsx"
Name sfile As "\\192.168.114.17\HVVHomeFolders\rmilhon\Development\Claims Audit Report\Claim_Audits_Professional" & "_" & Format(Date, "mmddyyyy") & ".xlsx"
'Repeat the above 2 lines for each file to add
'Send the email
objOutlookMsg.Send
'Clear out the objects
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub