andrewb90
Well-known Member
- Joined
- Dec 16, 2009
- Messages
- 1,077
Hello All,
I am using CDO to email employees schedules to them, and everything works great, until someone accidentally types in an incomplete email address. The red section is where the error pops up. Basically I know with other VBA I can an onError then just have it exit sub, however, I need to just have this error ignored and continue running the code.
Here's the code:
Is this doable? any help would be greatly appreciated.
I am using CDO to email employees schedules to them, and everything works great, until someone accidentally types in an incomplete email address. The red section is where the error pops up. Basically I know with other VBA I can an onError then just have it exit sub, however, I need to just have this error ignored and continue running the code.
Here's the code:
Code:
' http://www.blueclaw-db.com/access_email_gmail.htm' http://msdn.microsoft.com/en-us/library/ms872547%28EXCHG.65%29.aspx
' Add CDO reference for early binding method
' Tools > References > Microsoft CDO for Windows 2000 Library
' c:\windows\system32\cdosys.dll
' http://www.rondebruin.nl/cdo.htm 'Other cdo tips for cdo to Outlook from Excel
'CDO to gmail requires lowering your security:
'https://myaccount.google.com/security#connectedapps
'at the end set, Allow less secure apps: ON
Function Gmail(sendUsername As String, sendPassword As String, subject As String, _
textBody As String, sendTo As String, sendFrom As String, _
Optional sAttachment As String = "")
Dim cdomsg As New CDO.Message 'early binding method
'set cdomsg=new CDO.Message 'early binding only
'Dim cdomsg As Object 'late binding method
Set cdomsg = CreateObject("CDO.message") 'late binding method or early binding
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587 '25 or 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") = sendUsername
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = sendPassword
.Update
End With
' build email parts
With cdomsg
'.To = sendTo
.From = sendFrom
.subject = subject
.textBody = textBody
.BCC = sendTo
'.CC
'.ReplyTo = sendFrom
'.HTMLBody
'.HTMLBodyPart
If Dir(sAttachment) = "" Then sAttachment = ""
If sAttachment <> "" Then .AddAttachment (sAttachment)
[COLOR=#ff0000] .Send[/COLOR]
End With
Set cdomsg = Nothing
End Function
Is this doable? any help would be greatly appreciated.