Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook Automation - Test if Mail item was sent

Status
Not open for further replies.

glalsop

Technical User
Aug 9, 2003
435
US
Hello -

I am using automation in Office 2000 to control Outlook from Excel. I have a button on my worksheet to allow the user to email the workbook back to me directly from Excel. My problem is in determing if the e-mail was actually sent or if the user backed out and decided not to send it after I show Outlook. Here is my code:

Private Sub cmdEmail_Click()

Dim outApp As Outlook.Application
Dim outMail As Outlook.MailItem

Set outApp = CreateObject("Outlook.Application")
Set outMail = outApp.CreateItem(olMailItem)

'If the user tries to e-mail before they process the form, then that is okay as long as we
' validate the data and populate the Data worksheet first

If ValidInput = False Then
Exit Sub
End If

If MsgBox("Would you like to save the form before e-mailing?", vbYesNo, "Save") = vbYes Then
cmdSave_Click
End If

'We made it through the ValidateInput Sub, so we have good data
'...So we continue by loading the proper values on the Data worksheet
PopulateDataWS


With outMail
.To = "glalsop@emailaddress.com"
.Subject = "Talent Development Pilot - Manager Form"
.Attachments.Add ActiveWorkbook.FullName
.Display
End With


If outMail.Submitted = True Then
MsgBox "Thank you for completing the SunTrust Talent Development Pilot." & vbCrLf & _
"Your e-mail has been sent successfully."
Else
MsgBox "Your e-mail was NOT transmitted successfully." & vbCrLf & _
"In order for these forms to be processed properly, they must be re-submitted via e-mail.", _
, "Unsuccessful Transmission"
End If

Set outMail = Nothing
Set outApp = Nothing

End Sub

I have also tried the Sent property in place of the Submitted property but my If statement always evaluates to False even if I do send the e-mail.

Thanks in advance for any suggestions.


-Gary
 
Question for you. Why display the item? Why not just send it using .send rather than .display?

Assuming you have your reasons, one thought would be to search through the sent items folder of the user looking for a matching item to what you are sending.

Hope that helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top