The following code emails with attachment, however about 10 emails in a get a 2501 runtime error, can someone help it's driving me crazy?
Private Sub Command134_Click()
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim sToName As String
Dim sSubject As String
Dim sMessageBody As String
Set MyDb = CurrentDb()
Set rsEmail = MyDb.OpenRecordset("Contractors With Jobs Not Atteded On Time", dbOpenSnapshot)
Do Until rsEmail.EOF
Me.Combo130 = rsEmail!Contractor
sToName = rsEmail!Email
sSubject = "Jobs Not Achieving Attended On Time " & rsEmail!Email
sMessageBody = "Please Find Attached Jobs Not Achieving Attended On Time " & rsEmail!Contractor
Const cTIME = 1500 'in MilliSeconds
Call sSleep(cTIME)
DoCmd.SendObject acSendReport, "Jobs Not Achieving Attended On Time", acFormatRTF, sToName, , , sSubject, sMessageBody, False, False
rsEmail.MoveNext
Loop
Set MyDb = Nothing
Set rsEmail = Nothing
End Sub
I see no error handling in it. What happens if one of your contractors email address isn't on file? It has no instructions on what to do if an error occurs. So if a message fails to send for whatever reason it will stop, vs continuing and then telling you which messages failed to send.
Hope this helps,
Dan
"I am not a rocket scientist, I am a nuclear engineer." - Split_atom18
If my advice has been helpful to you, then please help me by clicking on the scales and adding to my reputation, Thanks!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks