Asked by:
Sub procedure sending emails stopped working

Question
-
I have a routine that sends invitations, it worked beautifully yesterday. Today the routine throws error 3265, object not found in collection.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim oApp As Outlook.Application
Dim oMail As MailItem
Dim testEmail As String
Dim strbody As String
Dim strbody2 As StringSet db = CurrentDb
Set rs = db.OpenRecordset("TestEmail", dbOpenDynaset)
Set oApp = Outlook.Application
Set oMail = oApp.CreateItem(olMailItem)
rs.MoveFirst
Do While Not rs.EOFstrbody = "<html><head><title>It's time to sign up for Summer Bible Study!!!</title><style>body{background-color: #FFFFFF;margin-margin-right: 20%;" & _
"borders: 2px dotted black;padding: 10px 10px 10px 10px;font-family: sans-serif;}</style></head>" & _
"<body><h1><center>It's time to sign up for Summer Bible Study!!!</center></h1>" & _
"<h2><center>June 30 - Aug 4, 2020</center></h2>" & _
"<p>Dear " & rs!First & ",<br></p>" & _
"<p>Text</p>" & _
"<p>Text</p></body></html>"
strbody2 = "<html><head><style>body{background-color: #FFFFFF;Margin-margin-right: 20%;borders: 2px dotted black;;padding: 10px 10px 10px 10px; font-family: sans-serif;}</style></head>" & _
"<p>Text</p>" & _
"<p>Text</p>" & _
"<p>Text</p></body></html>"
Set oMail = oApp.CreateItem(olMailItem)
oMail.To = rs!Email
oMail.Subject = "It's time to sign up for Summer Bible Study!!!"
oMail.BodyFormat = olFormatHTML
oMail.HTMLBody = strbody & strbody2
oMail.Display
oMail.Send
rs.MoveNext
LoopClosing code follows I am using Microsoft 365. As I said, it worked fine yesterday and i sent 300+ emails perfectly. Today i had just three more to send and it threw the error. Any thoughts?
MS - Teach me to fish
Saturday, June 20, 2020 6:13 PM
All replies
-
The only odd part I see is the use of both .Display and .Send. You probably want to comment out the first.
If that does not help, you need an error handler and if the error occurs again you can Resume to get back to the line where it happened, and check into it.
Also check your References. Any broken ones? Are they in the correct order?
-Tom. Microsoft Access MVP
Saturday, June 20, 2020 6:31 PM -
I forgot to say that when i went to debug, the object that was highlit was the definition of strbody. That has not been changed in my routine. I just removed my message text and replaced it with the word Text for the purposes of this forum.
I removed the display line but it still threw the error.
I checked and my references seem to be working. I am not sure what order the references should be in however. But i have not changed the order so, i don't know if that could be the issue.
MS - Teach me to fish
Saturday, June 20, 2020 8:45 PM -
Thanks Tom,
It turned out to be a problem with the table i was using. I set up a test table and didn't have the correct field names in the code. Basic stuff always gets me!
MS - Teach me to fish
- Proposed as answer by Tom van Stiphout (MVP)MVP Sunday, June 21, 2020 7:40 PM
Saturday, June 20, 2020 9:02 PM