Tracking Mail items being moved to folders

Status
Not open for further replies.

novemberskye

Member
Outlook version
Outlook 2013 64 bit
Email Account
Office 365 Exchange
Hi All,

I am looking to track some data when mail items are moved in Shared mail account to any subfolders within the account.
the code below is fired via Items_ItemAdd(ByVal item As Object)
- I don't want this restriction. I would like to track every time an item is moved anywhere within the shared mail account.

Issues:
1. Working on one by one movement from Inbox to 'Actioned' folder but not for multiple selected items (it's adding the number of selection correctly but the data it's recording is the same as the first item)
2. Restricted to moving from Inbox to Actioned

Help needed:
1. Code to allow to get "from" and "to" folders within the mail account
1.1 Code to get "from" folder name and "to" folder name
2. Code to record mail item data allowing multiple selected mail items


Appreciate your help in advance!!!


Code:
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim itm As Object
Dim msg As Outlook.MailItem
Dim sTime As String
Dim sSubj As String
Dim sCat As String
Dim sConID As String
 
Set objNS = GetNamespace("MAPI")
Set objFolder = objNS.Folders("contoso@microsoft.com.au") 
Set objFolder = objFolder.Folders("Inbox").Folders("Actioned")

  Set db = DBEngine.OpenDatabase("S:\....\dbo.mailtrackinglog.accdb")
  Set rs = db.OpenRecordset("tbl_mailmovements", dbOpenTable)

For Each msg In olApp.ActiveExplorer.Selection
Set msg = olApp.ActiveExplorer.Selection(1)
rcvdTime= msg.ReceivedTime
mSubj = msg.Subject
mConvId= msg.ConversationID
mCateg = msg.Categories

Next msg

with rst
.AddNew
.Fields( )  =  rcvdTime
.Fields( )  = mSubj
.Fields( )  = mConvId
.Fields( )  = mCateg

.Update

End With
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
- I don't want this restriction. I would like to track every time an item is moved anywhere within the shared mail account.
The only way to do it in VBA is to watch each folder (added to app startup) - you can use a bunch of itemadds that point to the working macro - unless you want to do it hourly or on a schedule - then you could walk all folders looking for new items.

sub Items_ItemAdd(ByVal item As Object)
trackingmacro item
end sub

sub SentItems_ItemAdd(ByVal item As Object)
trackingmacro item
end sub

etc.

For Each msg In olApp.ActiveExplorer.Selection
Set msg = olApp.ActiveExplorer.Selection(1)
the first line says to do all items in the selection, but the second line says to do the first selection. if you are using itemadd, you'd only want to do the newly added item - remove those lines and either use set msg = item or change msg to item

how to use itemadd macros: How to use an ItemAdd Macro
 

novemberskye

Member
Outlook version
Outlook 2013 64 bit
Email Account
Office 365 Exchange
the first line says to do all items in the selection, but the second line says to do the first selection. if you are using itemadd, you'd only want to do the newly added item - remove those lines and either use set msg = item or change msg to item

how to use itemadd macros: How to use an ItemAdd Macro
updated the 'for' statement to For x = 1 To myOlSel.Count
when I get to x = 2 I get an operation failed error

:(
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Do you want to run it on a selection? if so, use
For Each msg In olApp.ActiveExplorer.Selection

but get rid of this line -
Set msg = olApp.ActiveExplorer.Selection(1)

use with msg
'''do whatever
end with

next

The second macro on this page shows how to run macros on a selection : Working with All Items in a Folder or Selected Items

The problem is that you are mixing types of macros - if using an itemadd macro, you won't work with selections.
 

novemberskye

Member
Outlook version
Outlook 2013 64 bit
Email Account
Office 365 Exchange
See updated code below
Been knocked to a different path with new issues I am unable to solve even after half a day of research and testing. :( :( :(

the issue I am having is getting looping through the selected / moved item in the Destination Folder by each EntryID in the Item_Add event

Code:
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set objNS = GetNamespace("MAPI")
Set objFolder = objNS.Folders("## Shrared email account here ##")
Set objFolder = objFolder.Folders("Inbox").Folders("## SUBFOLDER HERE ##")

Dim olApp As Outlook.Application

  Set olApp = Outlook.Application
  Set Items = objFolder.Items
  objFolder.Items.Sort "[LastModificationTime]", True  ''''<--- does not look like it's working
 
End Sub


---------------------------------------

Public Sub Items_ItemAdd(ByVal Item As Object)

  Dim myNameSpace As Outlook.NameSpace
  Dim objFolder As Outlook.MAPIFolder
  Dim myDestFolder As Outlook.Folder
  Dim myDestItems As Outlook.Items

    Set myNameSpace = Application.GetNamespace("MAPI")
    Set objFolder = myNameSpace.Folders("## Shrared email account here ##")
    'Set objFolder = objFolder.Folders("Inbox")
   
  Set myInbox = objFolder.Folders("Inbox")
  Set myItems = myInbox.Items
  Set myDestFolder = objFolder.Folders("Inbox").Folders("## SUBFOLDER HERE ##")
  Set myDestItems = myDestFolder.Items

  On Error GoTo 0

    Dim myOlApp As Outlook.Application
    Dim myOlExp As Outlook.Explorer
    Dim myOlSel As Outlook.Selection
    Dim oMail As Outlook.MailItem
    Dim x, i, j As Integer
    Dim EntryIDCollection As String
    Dim myOlMItem As Outlook.MailItem
    Dim myOlAtts As Outlook.Attachments

    Set myOlApp = Outlook.Application
    Set myOlExp = myOlApp.ActiveExplorer
    Set myOlSel = myOlExp.Selection

 For Each Item In myOlSel
 EntryIDCollection = Item.EntryID & ","
 Next Item

  Set objNS = Application.GetNamespace("MAPI")
  strIDs = Split(EntryIDCollection, ",")
  For intX = 0 To UBound(strIDs)
  cMailItem = strIDs(intX)
  Set objEmail = objNS.GetItemFromID(cMailItem, Item.Parent.StoreID) '''''<----- ERROR HERE not able to get the mailitem by EntryID

   Set MyCurrentFolder = myOlExp.CurrentFolder
   Set msg = objEmail
   sTime = objEmail.ReceivedTime
   sSubj = objEmail.Subject
   sConID = objEmail.ConversationID
   sCat = objEmail.Categories
   sLMod = objEmail.LastModificationTime
   sFol = MyCurrentFolder
 

## 
Code here to upload mail item data to an access database
##

End sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
As Diane mentioned, you´re mixing different code. Use ItemAdd, if you want to handle on item added to a folder. Use the loop through selected items if you want to handle items selected by the user.

The For Each loop already loops through the items, giving you a ref on each selected item. Why do you first read only the IDs and then want to loop through that again?

Anyway, after the loop has finished the item variable is set to nothing. Thus you get an error trying to read a property of the item.

Since all items are from the same store, you can read the storeid from the folder object.
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
S mail tracking Exchange Server Administration 3
M Error in Mail Tracking ECP Website - Mail Tracking not working with DefaultDomain not found Error Exchange Server Administration 13
D Send e-mail from Word ignores Outlook Tracking Option defaults Using Outlook 1
L Attachment saving and tracking - PLEASE help! Outlook VBA and Custom Forms 5
R Outlook for Mac - Advanced Search and Tracking Sent Emails Using Outlook 0
H tracking time of emails Outlook VBA and Custom Forms 2
N Activity Tracking with Userform Outlook VBA and Custom Forms 4
S My Draft Emails Have Review Tracking Using Outlook 7
rino email campaign - tracking opened emails Outlook VBA and Custom Forms 6
C Problem tracking meeting responses Using Outlook 3
D tracking emails in outlook 2010 Using Outlook 1
C Rule to Handle Meeting Replies that updates tracking information Using Outlook 2
M Room Reservation request showed "None" in Tracking-View Tracking Status. Exchange Server Administration 0
C Tracking WHO deleted items in a Shared Mailbox Using Outlook 1
S How to remove tracking from printing - outlook 2010 Using Outlook 4
J Tracking sent emails Using Outlook 3
R Can't use "manage linking and tracking" BCM (Business Contact Manager) 10
P Tracking BCM Users BCM (Business Contact Manager) 1
K add an email to a business contact without linking/tracking sender BCM (Business Contact Manager) 0
K add an email to an account without linking and tracking the email address BCM (Business Contact Manager) 0
C Tracking Activities in Outlook Calendar Using Outlook 1
M Tracking Tasks Due Date Using Outlook 1
S Voting Buttons are Not Tracking Using Outlook 1
S Public Calendar Meeting Tracking Using Outlook 4
J Message Tracking from Exchange 2010 webservice Using Dotnet 2005 Exchange Server Administration 1
J Message Tracking using (EWS)webservice from Exchange 2010 Exchange Server Administration 2
T Outlook 2010 Tracking checkbox Using Outlook 2
T Outlook 2007 Tracking bug? Using Outlook 2
R Message Tracking Exchange Server Administration 2
M Changing default tracking folder from sent items folder to a user selected folder for individual ema Using Outlook 1
D Multiple attachment tracking Using Outlook 1
D Outlook Calendar invitation tracking issue Using Outlook 3
O Tracking non Office files automatically in Journal Using Outlook 1
S Message tracking logs - enabled on which servers? Exchange Server Administration 7
W Voting and tracking options issue Using Outlook 1
R Outlook 2007: Tracking when Emails have been read by a delegate Using Outlook 5
R Outlook 2007: Tracking when Emails have been read by a delegate Using Outlook 2
W Tracking Status on Meetings not working properly Using Outlook 2
W Having issues with voting and tracking options Using Outlook 1
S tracking options greyed Using Outlook 2
T Message size difference in Outlook and Exchange Tracking Using Outlook 1
S Message tracking and log check at exchange 2010 Exchange Server Administration 1
S Tracking does not work Using Outlook 1
A Re: Tracking issues with outlook 2007. Tracking information prints on a seperate page in outlook 20 Using Outlook 1
M Error messeage in Exchange 2010 SP! ECP Panel (Message Tracking) Using Outlook 3
O Outlook 2007 Meeting Request Not tracking all responses Using Outlook 5
J Appointment tracking not working correctly Using Outlook 4
G Restrict Message Tracking? Exchange Server Administration 7
A Tracking Contact Activities in Contact versus Journal Using Outlook 1
M Tracking in Calendar Using Outlook 2
Similar threads


















































Top