The following C# and Visual Basic for Applications (VBA) examples show how to use the Referred Entry Id property of Accounts to calculate the total Accounts that result from a Marketing Campaign.
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim bcmRootFolder As Outlook.Folder
Dim olFolders As Outlook.Folders
Dim bcmCampaignsFldr As Outlook.Folder
Dim newMarketingCampaign As Outlook.TaskItem
Dim newAccount1 As Outlook.ContactItem
Dim newAccount2 As Outlook.ContactItem
Dim existAccount As Outlook.ContactItem
Dim index As Integer
Dim userProp As Outlook.UserProperty
Set olApp = CreateObject("Outlook.Application")
Set objNS = olApp.GetNamespace("MAPI")
Set olFolders = objNS.Session.Folders
Set bcmRootFolder = olFolders("Business Contact Manager")
Set bcmAccountsFldr = bcmRootFolder.Folders("Accounts")
Set bcmCampaignsFldr = bcmRootFolder.Folders("Marketing Campaigns")
Set newMarketingCampaign = bcmCampaignsFldr.Items.Add("IPM.Task.BCM.Campaign")
newMarketingCampaign.Subject = "Sales Project with Wide World Importers"
If (newMarketingCampaign.UserProperties("Campaign Code") Is Nothing) Then
Set userProp = newMarketingCampaign.UserProperties.Add("Campaign Code", olText, False, False)
userProp.Value = "SP2"
End If
If (newMarketingCampaign.UserProperties("Campaign Type") Is Nothing) Then
Set userProp = newMarketingCampaign.UserProperties.Add("Campaign Type", olText, False, False)
userProp.Value = "Mass Advertisement"
End If
If (newMarketingCampaign.UserProperties("Budgeted Cost") Is Nothing) Then
Set userProp = newMarketingCampaign.UserProperties.Add("Budgeted Cost", olCurrency, False, False)
userProp.Value = 243456
End If
newMarketingCampaign.Save
Set newAccount1 = bcmAccountsFldr.Items.Add("IPM.Contact.BCM.Account")
newAccount1.FullName = "CompanyX"
newAccount1.FileAs = "CompanyX"
newAccount1.Email1Address = "someone@example.com"
If (newAccount1.UserProperties("Referred Entry Id") Is Nothing) Then
Set userProp = newAccount1.UserProperties.Add("Referred Entry Id", olText, False, False)
userProp.Value = newMarketingCampaign.EntryID
End If
newAccount1.Save
Set newAccount2 = bcmAccountsFldr.Items.Add("IPM.Contact.BCM.Contact")
newAccount2.FullName = "Wide World Importers"
newAccount2.FileAs = "Wide World Importers"
newAccount2.Email1Address = "someone@example.com"
If (newAccount2.UserProperties("Referred Entry Id") Is Nothing) Then
Set userProp = newAccount2.UserProperties.Add("Referred Entry Id", olText, False, False)
userProp.Value = newMarketingCampaign.EntryID
End If
newAccount2.Save
Dim TotalAccount As Integer
For index = 0 To (bcmAccountsFldr.Items.Count) - 1
If index = 0 Then
Set existAccount = bcmAccountsFldr.Items.GetFirst
Else
Set existAccount = bcmAccountsFldr.Items.GetNext
End If
If existAccount.ItemProperties("Referred Entry Id").Value = newMarketingCampaign.EntryID Then
TotalAccount = TotalAccount + 1
End If
Next
Debug.Print "Total Account: " & TotalAccount
Set newAccount1 = Nothing
Set newAccount2 = Nothing
Set newMarketingCampaign = Nothing
Set bcmCampaignsFldr = Nothing
Set bcmAccountsFldr = Nothing
Set olFolders = Nothing
Set bcmRootFolder = Nothing
Set objNS = Nothing
Set olApp = Nothing