Outlook 2010 Treat once an email with the ItemAdd event in a shared mailbox

oliv-

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi,
I need your opinion on my current project.

I have a a shared mailbox, and 2 or more users. Each user has the program.

When a new Email is added in the Inbox Folder of this shared mailbox, i want to Print it just once.

No problem for printing it.

s my test for whether only the first that starts the treatment is good ?

Code:
Dim WithEvents colInboxPartageeItems As Items

Private Sub Application_Startup()
    Dim NS As Outlook.NameSpace
    Set NS = Application.GetNamespace("MAPI")
        Set colInboxPartageeItems = NS.Stores("Sin-constr.gsn").GetDefaultFolder(olFolderInbox).Items
End Sub
   
Private Sub colInboxPartageeItems_ItemAdd(ByVal Item As Object)

    If InStr(1, Item.Subject, "Test", vbTextCompare) Then
        If Item.FlagIcon = 0 Then

            Item.FlagIcon = olGreenFlagIcon
            On Error Resume Next
            '    : Number : -2147221239 : Long : ThisOutlookSession.colInboxPartageeItems_ItemAdd
            Item.Save
            If Err.Number = -2147221239 Then
                Exit Sub
            Else
                Call go_Process_item(Item)
            End If


        End If
    End If
End Sub


Sub go_Process_item(Item)
    msgbox_uf.Show vbModeless
    msgbox_uf.TextBox1.MultiLine = True
    msgbox_uf.TextBox1 = Item & vbTab & Date & vbTab & Time & vbCrLf & msgbox_uf.TextBox1
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The IF should take of it - but Outlook 2010 doesn't use the colored flags. Use Categories or the completed flag instead. (if the flag or category doesn't stick, you'll need to item.save too.)

But... if more than one computer receives the message at the same time, both will print it. if all 3 are never running at the same time, then it won't be a problem.
 

oliv-

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
potentially , multiple computers can receive mail almost the same time , I took the test !
But the first that saves, causes an error -2147221239 in the others, if the IF does not lead to the exit.

I will test it with Category.
 

Similar threads


Top