ContactItem object

The ContactItem object allows you to work with a contact. An Items collection is associated with each MAPIFolder object. The collection contains all of the contact items in the folder.

Creating a new contact

Use the CreateItem method from the Application object to create a new contact. You must specify the item type with the olContactItem constant from the olItemType enumeration. The contact is automatically added to the Items collection.

{Create a new contact.}
contactItem = app.CreateItem(Outlook.olContactItem);

You can also use the Add method from the Items collection to create a new contact. You must specify the item type with the olContactItem constant.

{Add a new contact to the Items collection.}
contactItem = folder.Items.Add(Outlook.olContactItem);

Retrieving an existing contact

You can retrieve a contact from the Items collection associated with the Item method by the number associated with the contact.

{Retrieve the third contact from the Items collection.}
contactItem = folder.Items.Item(3);

You can also access contacts by the name of the contact.

{Retrieve the contact named "Kim Akers".}
contactItem = folder.Items.Item("Kim Akers");

Displaying a contact

Use the Display method to display a contact in a window.

{Display the contact.}
contactItem.Display();

Setting and retrieving a contact’s first name

The FirstName property allows you to set or retrieve a contact’s first name. Setting the FirstName property specifies the first name of a contact.

{Set the contact’s first name.}
contactItem.FirstName = "Kim";

You can also use the FirstName property to retrieve the first name of a contact.

{Retrieve the contact’s first name.}
aName = str(contactItem.FirstName);

Setting and retrieving a contact’s last name

The LastName property allows you to set or retrieve a contact’s last name. Setting the LastName property specifies the last name of a contact.

{Set the contact’s last name.}
contactItem.LastName = "Akers";

You can also use the LastName property to retrieve the last name of a contact.

{Retrieve the contact’s last name.}
aName = str(contactItem.LastName);

Setting and retrieving a contact’s job title

The JobTitle property allows you to set or retrieve a contact’s job title. Setting the JobTitle property specifies the job title of a contact.

{Set the contact’s job title.}
contactItem.JobTitle = "Accountant";

You can also use the JobTitle property to retrieve the job title of a contact.

{Retrieve the contact’s job title.}
jobTitle = str(contactItem.JobTitle);

Saving a contact as a file

If you have previously saved a contact, use the Save method to save the contact.

{Save an existing contact.}
contactItem.Save();

To save a new contact, use the SaveAs method. You must supply the filename for the contact. You can also specify the saved contact’s file type with a constant from the olSaveAsType enumeration. If you do not specify a constant from the olSaveAsType enumeration, the contact is saved as the message file type.

{Save a new contact as a text file.}
contactItem.SaveAs("C:\RESM\KIMAKERS.TXT", Outlook.olTXT);

You can use the Saved property to find out if a contact has been saved. The Saved property returns true if the contact has been saved. Otherwise, it returns false. You cannot set the value of the Saved property.

{If a contact has not been saved, save it.}
if(not contactItem.Saved) then
	contactItem.Save();
end if;

Deleting a contact

To delete a contact, use the Delete method.

{Delete the contact.}
contactItem.Delete();

Contacts that are deleted are sent to the Deleted Items folder. However, if a contact is deleted from the Deleted Items folder, it is permanently deleted.


Closing a contact

Use the Close method to close a contact. You can use the constants contained in the olInspectorSave enumeration to specify the whether a contact is saved when it is closed. To save a contact as a contact, use the Close method and specify the olSave constant.

{Close the contact and save all changes without asking the user.}
contactItem.Close(Outlook.olSave);


Documentation Feedback