events - Detect if the last selected email has been marked as read and prompt to save -


my outlook vba code aims @ doing following: in event of selection change (i.e. user clicks on different email in inbox)

if [the selected email 'unread' , became 'read'] prompt user save previous email else nothing end if 

to used explorer_selectionchange event. problem i'm facing outlook takes 1 2 seconds before marks previous email read! code gets executed before these 2 seconds pass. hence sees previous email unread! :(

i tried introduce pause sub didn't work. outlook waits until code finishes including pause before in turn waits 1 2 seconds , mark previous email read.

so in summary question is: there event identifies when selected email marked read?? (ps: tried mailitem.read event instantaneous , applies 'read , unread' emails]

here part of code tries achieve above described functionality:

public withevents myolexp outlook.explorer dim flag integer dim omail outlook.mailitem  private sub application_startup() dim objitem object  set myolexp = application.activeexplorer enviro = cstr(environ("userprofile"))  'identify status of selected email @ startup each objitem in myolexp.selection     if objitem.messageclass = "ipm.note"         set omail = objitem     end if next  if omail.unread     flag = 1 'means current selection unread email else     flag = 0 'means current selection has been read before end if  end sub   private sub myolexp_selectionchange() 'if previous selected email unread if flag = 1     if omail.unread = false         msgbox "previous email has been read want save?"         '^^this problem happens: selected email seen read code         'because outlook takes 1-2 seconds after selection change event before marks email read!!     else         msgbox "previous email still marked unread, nothing"         '^^i getting outcom when change selection unread email email!     end if      'now identify status of newly selected email     each objitem in myolexp.selection         if objitem.messageclass = "ipm.note"             set omail = objitem         end if     next      if omail.unread         flag = 1 'means current selection unread email     else         flag = 0 'means current selection has been read before     end if  else     ' flag = 0 i.e previous email read     ' identify status of newly selected item.     each objitem in myolexp.selection         if objitem.messageclass = "ipm.note"             set omail = objitem         end if     next     if omail.unread         flag = 1     else         flag = 0     end if end if  end sub 

i hope managed formulate question clearly! appreciated.

many thanks

once set flag = 1, omail.unread status not matter.

if flag = 1      ' remove test     'if omail.unread = false          msgbox "... 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -