How to handle sent message

  • Thread starter Thread starter Ronster
  • Start date Start date
R

Ronster

Hi everyone

I would like to know how can I handle if a user have sent the email
when using the Display (vbModal) option.

I am using the modal option because I need to have the code to stop
and when the event is trigger I am returning a true or false value.

Here is a potion of my code. The portion where I handle if user has
not sent the email work’s fine and I display a message box .
Where I have the problem is when user does sent the email. The line
of code (If Not .Sent Then) get me an error Item has been move or
delete. Is there a way I can handle this problem


Thank you all for your time.

Ron



' Add recipients to MailItem object's Recipients collection.
With objNewMail
.Recipients.Add txtTo

' Let Outlook verify that these are valid recipients.
blnResolved = .Recipients.ResolveAll

' Set MailItem object's Subject and Body properties.
.Subject = txtSubject
.Body = txtMessage

' Set MailItem object's Importance property.
.Importance = olImportanceHigh
If blnResolved = False Then ' invalid recipient

'User has enter an invalid user name
MsgBox "Invalid user name. Make another selection",
vbInformation

Else

.ReadReceiptRequested = True
' Send or Display MailItem depending on user's choice.
If bDisplayMsg Then

.Display (vbModal)

If Not .Sent Then ' user did not send the email

MsgBox ("must send it: " & .To)
bSent = False
Exit Function

End If
Else
.Send
bSent = True
End If
End If
End With
 
If an item has been sent it has been moved. And you really don't want
to display an item modally, it leads to all sorts of problems
including ghost Inspectors that are left around.

Instead of that you'd be better off trapping the Item.Close and .Send
events for that item and setting a value based on those events and
what happens in them. Then handling Inspector.Close would give you an
event where you can do whatever you want with that value.

If items are being moved to the Sent Items folder after being sent you
can also use an ItemAdd event handler for the Items collection of the
Sent Items folder to handle items after they are sent out.
 
Back
Top