Delete the Read Email And Open the Next One

See how to open the next email and delete the one you've just read.

Last modified: 2007/01/08 | Accessed: 49.109  | #40
◀ Previous sample Next sample ▶
Reporter Reporter
VBOffice Reporter is an easy to use tool for data analysis and reporting in Outlook. A single click, for instance, allows you to see the number of hours planned for meetings the next month.

If you have opened an e-mail then you can use two toolbar buttons to move to the next or previous e-mail. If you move on and want to delete the read e-mail then that's not easy: Either you switch to the folder view, select the formerly read e-mail and hit detele, or you have to delete the currently opened e-mail before moving to the next item - but then the window closes and you can't move easily to the next item.

This sample shows how to move with a single click to the next e-mail and delete the read one.

Note: The sample doesn't work in Outlook 2000 if word is your mail editor because then the NewInspector event doesn't fire.

When the e-mail window is opened, please customize the toolbar and create a new button that calls the 'NextItemAndDeleteCurrent' function.

tip  How to add macros to Outlook
Private WithEvents m_Inspectors As Outlook.Inspectors
Private WithEvents m_Inspector As Outlook.Inspector
Private WithEvents m_NextButton As Office.CommandBarButton

Private Sub Application_Startup()
  Set m_Inspectors = Application.Inspectors
End Sub

Private Sub m_Inspector_Close()
  Set m_NextButton = Nothing
  Set m_Inspector = Nothing
End Sub

Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
  Dim obj As Object

  If Len(Inspector.CurrentItem.EntryID) Then
    Set m_Inspector = Inspector
    Set obj = Inspector.CommandBars.FindControl(, 360)
    If TypeOf obj Is Office.CommandBarPopup Then
      Set m_NextButton = obj.Controls(1)
      Set m_NextButton = obj
    End If
  End If
End Sub

Public Sub NextItemAndDeleteCurrent()
  Dim CurrItem As Object

  Set CurrItem = Application.ActiveInspector.CurrentItem
  If Len(CurrItem.EntryID) Then
  End If
End Sub
Determine the "identity" of your emails. Set with SAM the sender and the folder folder for sent items with the help of rules.
email  Send a message