none
How to keep only one mail open at a time with VBA RRS feed

  • General discussion

  • Dear All,

    In context to outlook 2007,
    I want to write code which will help to keep only one mail open at a time, ie., in the Outlook Inbox, as there would be several mails, when I open one mail, it opens in a seperate window, when I try to open another mail item, it should display a message box or donot allow the user to open another mail or close the previous mail and open the current selection.

    Can any one help me to do this?

    With thanks and regards,
    Repath Athyala.


    Love the Love that Loves the Love and Hate the Love that Loves the Hate.

    Tuesday, July 23, 2013 12:28 PM

All replies

  • The window for an item is an Inspector. You can handle Inspectors.NewInspector() and set an Inspector object and handlers for the Inspector and the Inspector.CurrentItem. In the Open() event for the item you can cancel the opening of the item if Inspectors.Count > 1.

    Neither NewInspector() nor Inspector.Activate() have Cancel arguments, so your first shot of closing the iten would be in the Open() event. Set Close to True if there are more than 1 Inspectors.


    Ken Slovak MVP - Outlook

    Tuesday, July 23, 2013 4:55 PM
    Moderator
  • Thank you very much sir, I tried the way you told and got the solution.,
    Can you please help me in the following context:

    I am working on a small Common mail box where the mail box is shared among 4 other users. Mails requests keep flowing into INBOX, these mails are divided among the 4 users by moving into their respective folders (say _JoeFolder, _JaneFolder, _SuseFolder folders created after their names).
    I wrote code to move mails from Inbox to user folders, but now the situtation:

    • Users can also move mails between user folders like (user Joe can move an item from _JoeFolder to Jane's folder or Jane can move an item from _JaneFolder to Suse's Folder...)
    • Can you please help me as to where I can write code (which event) and if possible sample code to move between user folders.
    • Users should not be able to move mails from their respective folders back to Inbox.
    • This would be of great help to me in this project.

    My thought is to:

    • Create a folder variable eg: _userFolder where folder gets the name after selecting the folder.
    • Pass this variable to a function and stop moving any content from this folder.

    Is this possible, if so , can you please help me with the code and the event that I should handle, or suggest me some code that would help me do the task.

    with many thanks in advance,
    repath athyala.


    Love the Love that Loves the Love and Hate the Love that Loves the Hate.

    Wednesday, July 24, 2013 4:04 AM
  • Each Folder object has a BeforeItemMove(Item As Object, MoveTo As Folder, Cancel As Boolean) event. You can check to see if the MoveTo folder is the same folder as the Inbox or any other folder and set Cancel to True if you want to disallow the move.

    I would get the EntryID of the folder and use the NameSpace.CompareEntryIDs() method to see if the folders match. If so I'd disallow the move.


    Ken Slovak MVP - Outlook

    Wednesday, July 24, 2013 2:24 PM
    Moderator