Which way should I add an AddressEntry?

S

Shelby

Hi,
how do I add a ContactItem to a specific AddressList?
I have populate a ListBox with user's Address Book.
User will select the specific Address Book and an AddressEntry will be added
into that AddressList.

So do I add the entry like this:
AddressList = oNs.AddressLists.Item(UserSelectedIndex)
myentry = AddressList.AddressEntries.Add("SMTP", "testtest",
"(e-mail address removed)")
myentry.Update()
(If I add it this way, I do not have access to other properties such as
CompanyName, Birthday etc etc)


Or like this:
sCtact = oApp.CreateItem(Outlook.OlItemType.olContactItem)
sCtact.FullName = "Test 123"
sCtact.CompanyName = "His Company Name"
sCtact.Birthday= "His birthday"
sCtact.Email1Address = (e-mail address removed)
sCtact.Close(Outlook.OlInspectorClose.olSave)
(If I add it this way, it will not be added to user's specified address
book)


Thanks.
 
K

Ken Slovak - [MVP - Outlook]

The second way adds it to the default Contacts folder. Either use the Add
method of the Items collection of the folder you want or create it in the
default Contacts folder and use the Move function to move it to the folder
you want after creating it.
 
S

Shelby

Hi,
yes I notice that the second method adds to the default Contacts folder.
So if I use the second method, I need to parse the folder path to the Move
method.
The question is, how can I get the folder path with the"AddressList Index"?
Because I have populated a list box with the AddressList Name and Index.
When user select the specific AddressList, it will be added to that
AddressList.

Thanks
Shelby
 
K

Ken Slovak - [MVP - Outlook]

The Index property of an AddressList just gives you the current number of
that list in the AddressLists collection. That is not necessarily a
persistent value and can even change during an Outlook session if additional
AddressList's are added to that collection. So I would not depend on that
value for anything.

AFAIK there is no direct way to correlate an AddressList with a specific
Contacts folder other than brute force. I would iterate recursively all the
folders below Inbox.Parent for folders and subfolders that are Contacts
folders and store that information along with the folder paths and then try
to match up the names of the folders with the AddressList name. There may be
better ways but I'm not aware of them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top