The following C# and Visual Basic for Applications (VBA) examples show how to use the Referred Entry Id property of Business Contacts to calculate the total Business Contacts 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 bcmContactsFldr As Outlook.Folder
Dim newMarketingCampaign As Outlook.TaskItem
Dim newContact1 As Outlook.ContactItem
Dim newContact2 As Outlook.ContactItem
Dim existContact 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 bcmContactsFldr = bcmRootFolder.Folders("Business Contacts")
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 newContact1 = bcmContactsFldr.Items.Add("IPM.Contact.BCM.Contact")
newContact1.FullName = "John Smith"
newContact1.FileAs = "John Smith"
newContact1.Email1Address = "someone@example.com"
If (newContact1.UserProperties("Referred Entry Id") Is Nothing) Then
Set userProp = newContact1.UserProperties.Add("Referred Entry Id", olText, False, False)
userProp.Value = newMarketingCampaign.EntryID
End If
newContact1.Save
Set newContact2 = bcmContactsFldr.Items.Add("IPM.Contact.BCM.Contact")
newContact2.FullName = "Nikolay Grachev"
newContact2.FileAs = "Nikolay Grachev"
newContact2.Email1Address = "someone@example.com"
If (newContact2.UserProperties("Referred Entry Id") Is Nothing) Then
Set userProp = newContact2.UserProperties.Add("Referred Entry Id", olText, False, False)
userProp.Value = newMarketingCampaign.EntryID
End If
newContact2.Save
Dim TotalContact As Integer
For index = 1 To (bcmContactsFldr.Items.count) Step 1
Set existContact = bcmContactsFldr.Items(index)
If existContact.ItemProperties("Referred Entry Id").Value = newMarketingCampaign.EntryID Then
TotalContact = TotalContact + 1
End If
Next
Debug.Print "Total Contact: " & TotalContact
Set newContact1 = Nothing
Set newContact2 = Nothing
Set newMarketingCampaign = Nothing
Set bcmCampaignsFldr = Nothing
Set olFolders = Nothing
Set bcmRootFolder = Nothing
Set objNS = Nothing
Set olApp = Nothing