Hi, I have the following code to email some reports out of my access DB. This runs automatic with a task scheduler and works perfect except when my internet connection is down (happens quite often), the problem is when there is not internet and the CDO cannot complete it hangs my program and the task scheduler will not close the process.
Is there a way to add some error handling to this code so if after a certain amount of time or if there is no connection it kills and ends the code?
Many thanks.
Fen
Public Function send_email_reports()
Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp."
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
.Update
End With
' build email parts
With cdomsg
.To = "@gmail.com"
.From = ""
.Subject = " Daily Reports Attached " & Date & "-" & Time
.TextBody = "Daily DriveNow Reports. *** This is an automatically generated email, please do not reply. . ***"""
.AddAttachment ("")
.Send
End With
Set cdomsg = Nothing
End Function
Is there a way to add some error handling to this code so if after a certain amount of time or if there is no connection it kills and ends the code?
Many thanks.
Fen
Public Function send_email_reports()
Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp."
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
.Update
End With
' build email parts
With cdomsg
.To = "@gmail.com"
.From = ""
.Subject = " Daily Reports Attached " & Date & "-" & Time
.TextBody = "Daily DriveNow Reports. *** This is an automatically generated email, please do not reply. . ***"""
.AddAttachment ("")
.Send
End With
Set cdomsg = Nothing
End Function