Try something like
Public Function SendTKEmailTo(strMailFrom, strMailTo, strMailCC, strSubject,
strMailBody)
On Error GoTo Error_Handler
Set myMailApp = CreateObject("CDO.Message")
myMailApp.Subject = strSubject
myMailApp.Sender = strMailFrom
myMailApp.To = strMailTo
myMailApp.CC = strMailCC
myMailApp.TextBody = strMailBody
myMailApp.Configuration.Fields.Item _
("
http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
myMailApp.Configuration.Fields.Item _
("
http://schemas.microsoft.com/cdo/configuration/smtpserver") = "our
company 's smtp server"
myMailApp.Configuration.Fields.Item _
("
http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
myMailApp.Configuration.Fields.Update
myMailApp.Send
Set myMailApp = Nothing
If Err.Number = 0 Then Exit Function
Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: SendTKEmailTo" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Function
End Function
Now run it again and pay attention to the error number that is raised so you
can trap it by switching the
Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: SendTKEmailTo" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Function
With something like
Error_Handler:
If Err.Number = 1111 Then
Resume Next
Else
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: SendTKEmailTo" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Function
End If
Where you replace 1111 with your error code and you tell access to simple
continue with the routine anyways.
Try it and post back if you still have problems.
--
Hope this helps,
Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples:
http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.