I have an intermittent Excel VBA problem when sending via Outlook.
20 or 30 times a day my clients send email files. About once a week the email doesn't send. It's not in the Outbox or Sent. We only find out when we receive a physical sample without the corresponding email, usually the next day.
The relevant Excel VBA code:
'[bunch of code that sets everything up in order to send]
Err.Clear
On Error Resume Next
Set OutMail = oOutlook.CreateItem(0) ' [oOutlook is a previously created object which is an instance of Outlook]
With OutMail
.To = Address ' [Address=email I have pre-filled]
.Subject = "Swabs File"
.body = vbAns ' [vbAns = variant I have pre-filled]
.Attachments.Add (Dir) ' [Dir = string which is the name of the file]
.send
End With
'Error trap if there is any problem at all
If Err Then
MsgBox ("Problem with Outlook - Failed to Send. Please try again")
Exit Sub
else
MsgBox ("Your file has been sent")
End If
When the problem occurs the error isn't trapped, and the client thinks they have successfully sent the file.
How can I trap the error?