What I am doing:
1. Automated Process Kicks off 8 p.m. every night
2. Process concludes by sending out and e-mail with attachment.
What is happening:
1. If I cycle thought no issues
2. If I manually kick off the process no issue
3. Each night the entire process runs except the e-mail
4. Receiving error code 91 (object or with not set) on that module
5. I have 2 databases and both fail for the same reason
I don't believe it is a passed variable issue as the file is found updated in the correct spot and the myname is a variable passed through several module which if in error would cause issue much further upstream.
My suspicion is that it is outlook permission related with something to do with waking from sleep but my google skills are failing me. Plan to re-dim proc after each possible failure to find which item is failing specifically but holding out hope it is simple and I am stupid.
Public Function send_e_mail(file As String, myname)
Dim errored As String
Dim proc As String
Dim Report As String
proc = "sendemail"
Sleep 1000
Dim oApp As Outlook.Application
Dim oMail As MailItem
On Error GoTo failure
Set oApp = CreateObject("Outlook.application")
Set oMail = oApp.CreateItem(olMailItem)
oMail.HTMLBody = "Daily Orders & Routing is updated and attached."
oMail.Subject = "Daily Orders has been updated for" & " " & Now()
With oMail
.Attachments.Add (file)
.To = DLookup("[E-mail]", "MyAccounts", "[Company] ='" & myname & "'")
.send
End With
Set oMail = Nothing
Set oApp = Nothing
GoTo exits
failure:
errored = proc & " " & err & " " & err.Description
Call handleerror(errored, proc)
Resume Next
exits:
End Function
1. Automated Process Kicks off 8 p.m. every night
2. Process concludes by sending out and e-mail with attachment.
What is happening:
1. If I cycle thought no issues
2. If I manually kick off the process no issue
3. Each night the entire process runs except the e-mail
4. Receiving error code 91 (object or with not set) on that module
5. I have 2 databases and both fail for the same reason
I don't believe it is a passed variable issue as the file is found updated in the correct spot and the myname is a variable passed through several module which if in error would cause issue much further upstream.
My suspicion is that it is outlook permission related with something to do with waking from sleep but my google skills are failing me. Plan to re-dim proc after each possible failure to find which item is failing specifically but holding out hope it is simple and I am stupid.
Public Function send_e_mail(file As String, myname)
Dim errored As String
Dim proc As String
Dim Report As String
proc = "sendemail"
Sleep 1000
Dim oApp As Outlook.Application
Dim oMail As MailItem
On Error GoTo failure
Set oApp = CreateObject("Outlook.application")
Set oMail = oApp.CreateItem(olMailItem)
oMail.HTMLBody = "Daily Orders & Routing is updated and attached."
oMail.Subject = "Daily Orders has been updated for" & " " & Now()
With oMail
.Attachments.Add (file)
.To = DLookup("[E-mail]", "MyAccounts", "[Company] ='" & myname & "'")
.send
End With
Set oMail = Nothing
Set oApp = Nothing
GoTo exits
failure:
errored = proc & " " & err & " " & err.Description
Call handleerror(errored, proc)
Resume Next
exits:
End Function