How to get connected contacts in appointment item?

D

Dikbill

Hi there,

When I create an appointment item in Outlook a can connect contact items
with the button on the bottom of the screen, even contacts that don't have
an email
address can be choosen there!

My question is, where is that data stored?
I have a program written in VB 2005 with Outlook 2003 SP2.

When I have the Outlook appointment available in my code as object, I can
read and write
allmost all values but I can't find a value where the connected contacts are
stored.

Anyone have an idea how to get this info?
If it exists I also want to write values!

Thanx a lot,

Dikbill, The Netherlands
(e-mail address removed)
 
K

Ken Slovak - [MVP - Outlook]

Use the Links collection, which takes ContactItem objects in its Add method.
 
D

Dikbill

Ken tx for your quick answer!

Lazy as I am, do you have an example of this links collection?

Thnx,

Dikbill, The Netherlands,
(e-mail address removed)
 
K

Ken Slovak - [MVP - Outlook]

Dim oContact As Outlook.ContactItem
Dim AlreadyInstantiatedContact As Outlook.ContactItem

Set oContact = Application.ActiveInspector.Links.Item(1)

Set oContact =
Application.ActiveInspector.Links.Add(AlreadyInstantiatedContact)
 
D

Dikbill

Ken,

Thnx again! I've got it working, but....... :)

I get the following error on the instruction oContact = Item.Links.Item(1)
In my case Item is the active Explorer!

System.InvalidCastException was unhandled by user code
Message="Unable to cast COM object of type 'System.__ComObject' to
interface type 'Microsoft.Office.Interop.Outlook.ContactItem'. This
operation failed because the QueryInterface call on the COM component for
the interface with IID '{00063021-0000-0000-C000-000000000046}' failed due
to the following error: Interface wordt niet ondersteund (Exception from
HRESULT: 0x80004002 (E_NOINTERFACE))."

I've solved this error to declare an object:
Dim olContact As Outlook.Link
olContact = Item.Links.Item(1)
This wil prevent the error
An Outlook.Link object, in my case olContact , has the following properties,
as you already know ofcourse,
Application
Class
Item
Name
Parent
Session
Type
In the Name property I can get the Name value (Duh)
But what I need is the EntryID value of the Contact Item.
This is because I want a unique ID.
Multiple Contacts with the exactly the same name can occur in Outlook.
Is there a way to get the EntryID of the linked contact(s)??

Thnx for your time again...


Dikbill, The Netherlands,
(e-mail address removed)
 
K

Ken Slovak - [MVP - Outlook]

Item should certainly not be an Explorer.

Sorry about that, I've been using Links for so long as MAPI properties I
forgot the odd casting you need to get a contact item out of a link. Try
this:

Dim olContact As Outlook.ContactItem

olContact = Item.Links.Item(1).Parent

strEntryID = olContact.EntryID
strFullName = olContact.FullName

etc.

That's necessary even though the Type returned for a Link item is 40, which
is olContact. Weird but you have to use the Link item's Parent property to
get a ContactItem that won't throw an exception for the cast.
 
D

Dikbill

Ken,

Thnx but

olContact = Item.Links.Item(1).Parent

returns the appointment item where the contacts are connected from
so olContact will contain the appointment object ;-)

Any suggestions??

Tx

Dikbill, The Netherlands,
(e-mail address removed)
 
K

Ken Slovak - [MVP - Outlook]

You're correct, I tested this here with a contact item so that fooled me.

I'd have to say after looking at it again and reviewing some of my old code
that worked with the Links collection that the only thing you're going to be
able to get back using the Outlook object model is the name property of the
link item.
 
D

Dikbill

Ken,

No worry's :)
Yesterday late in the afternoon I've solved the problem!

Item is the filtered Appointment item with some contacts linked to it.
Item = olns.GetItemFromID(myAppt.EntryID, StoreID)

Dim iLinkItems As Integer = 0

Dim olinkitem As Outlook.Link = Nothing

For iLinkItems = 1 To Item.Links.count

olinkitem = Item.Links.Item(iLinkItems)

MsgBox("EntryID= " & olinkitem.Item.EntryID & " FullName= " &
olinkitem.Item.FullName)

Next

With this code I can get all data from the linked contacts!
The most important is the EntryID for identification :)

Thanx for your help and succes with your projects!
You've save me a great deal of search time ;-)

Dikbill, The Netherlands
(e-mail address removed)
 

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