Share via


Select a Marketing Campaign

Outlook Developer Reference
Select a Marketing Campaign

To select a Marketing Campaign object, use the Collection.Find method to select an item from the MAPI Folder. The Find method accepts as input a String query and filters items based on the query. If there are more than one items matching the query, only the first match is returned.

The following C# and Visual Basic for Applications (VBA) examples show how to select an existing Marketing Campaign object.

  private void SelectMarketingCampaign()
{ 

Outlook.ApplicationClass _app = new Outlook.ApplicationClass(); Outlook.Application olApp = (Outlook.Application)_app; Outlook.NameSpace olNameSpace = _app.GetNamespace("MAPI"); Outlook.Folders folders = olNameSpace.Session.Folders; Outlook.Folder bcmRootFolder = (Outlook.Folder)folders["Business Contact Manager"]; Outlook.Folder campaignsFolder = (Outlook.Folder)bcmRootFolder.Folders["Marketing Campaigns"];

string strQuery = "[Subject] = 'New Marketing Campaign'";

Outlook.TaskItem campaignItem = (Outlook.TaskItem)campaignsFolder.Items.Find(strQuery); if (campaignItem != null) { Console.WriteLine("Marketing Campaign Found"); }

else { Console.WriteLine("Marketing Campaign Not Found"); }

Console.ReadLine();

}

  Sub ReadMarketingCampaign() 

Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim olFolders As Outlook.Folders Dim bcmRootFolder As Outlook.Folder Dim bcmCampaignsFldr As Outlook.Folder

Dim existMarketingCampaign As Outlook.TaskItem

Set olApp = CreateObject("Outlook.Application") Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Session.Folders

Set bcmRootFolder = olFolders("Business Contact Manager") Set bcmCampaignsFldr = bcmRootFolder.Folders("Marketing Campaigns")

Set existMarketingCampaign = bcmCampaignsFldr.Items.Find("[Subject] = 'Sales Project with Wide World Importers'") If Not TypeName(existMarketingCampaign) = "Nothing" Then

  MsgBox ("Marketing Campaign found") 

Else

  MsgBox ("Marketing Campaign not found") 

End If

Set existMarketingCampaign = Nothing Set bcmCampaignsFldr = Nothing Set bcmRootFolder = Nothing Set olFolders = Nothing Set objNS = Nothing Set olApp = Nothing

End Sub

See Also

Create a Marketing Campaign | Edit a Marketing Campaign | Delete a Marketing Campaign | Office Developer Center: Outlook 2007