Hello,
I have code that in win7 successfully automated sending emails to recipients. I've recently upgraded to win10 and this code has stopped working. It errors on the link .send with the error "Runtime error '287': Application defined or object defined error".
I think this could be because the .to and .cc fields are not set but I'm not sure. When I look in the locals window, you can see that the .cc .to (not in attached screenshot) and .htmlbody fields are not set even though they are defined in the code. My code is below with the set defining "text" slightly edited because it is long and boring in the original.
I've done a bit of a google and it appears that I'm not the only one with this problem, but I wasn't quite able to ascertain what to do from my search results so thought I would ask here.
Code:
Set reviewList = CurrentDb.OpenRecordset("SELECT * FROM tblIPScomments WHERE [Plan]=" & Me.txtHiddenID & " AND isnull([EmailSent])")
Set Plan = CurrentDb.OpenRecordset("SELECT * FROM tblIPS WHERE [ID]=" & Me.txtHiddenID)
Set oApp = CreateObject("Outlook.Application")
' Loop through the recordset and email the reviewers about their responsibilities
If reviewList.BOF And reviewList.EOF Then
' Request for review emails already sent, inform the user and exit
text = "Request for review emails have already been sent for this plan."
MsgBox text, vbOKOnly, "Duplicated Action"
Exit Sub
End If
reviewList.MoveFirst
Do Until reviewList.EOF
' First process any Main reviewers. We have already checked that these are always specified
' EMAIL TEXT
' Line 1: Warning that this is an automated email and not to reply to it. This is always the same
text = "Long and boring section setting up the body of the email. Removed"
' END EMAIL TEXT
'Send the email
Set oMail = oApp.CreateItem(olMailItem)
' On Error Resume Next
With oMail
.To = DLookup("[email]", "tblUsers", "[ID]=" & reviewList("MainReviewer"))
.cc = DLookup("[email]", "tblUsers", "[ID]=" & reviewList("BackupReviewer"))
.BCC = ""
.subject = "Please Review IPS Plan " & Plan("WorkPlan") & " by " & reviewList("DueDate")
' If High Urgency is set, send as important
If Me.chkUrgency Then .Importance = olImportanceHigh
.HTMLBody = text
.Send ' <- ERRORS HERE
End With
On Error GoTo 0
' Mark the email as having been sent
reviewList.Edit
reviewList("EmailSent") = Now
reviewList.Update
' Move to the next reviewer
reviewList.MoveNext
Loop
Set oMail = Nothing
Set oApp = Nothing