Can you 'find' a contact from code in outlook - Resolved
I'm writing an app that will populate contacts from a database into outlook. I've stored the contact reference from the database in the customerID field of the contact in outlook (I chose the customerID field arbitrarily if anyone knows a better one which isn't visible to the user, please let me know)
I now want to be able to find a given contact in outlook from the db reference. Is there a simple way of doing this?
If there's not an outlook API call I could write a recursive algorithm that searched through the contacts folder and sub folders checking the customerID field of each contact it finds but I suspect that might be a little on the slow side. Any better suggestions?
Re: Can you 'find' a contact from code in outlook
The .EntryID field of any Outlook object is the way to go. You even have a function to get a specific item.
VB Code:
Dim oContact As Outlook.ContactItem
Set oContact = Application.GetNamespace("MAPI").GetItemFromID("EntryID", "EntryIDStore")
Re: Can you 'find' a contact from code in outlook
Oooh! That sounds like what I'm after :D . Does the GetItemFromID method search subfolders or just the folder it's called against?
Re: Can you 'find' a contact from code in outlook
When I came to try it out I realised I displayed my ignorance with that last question :eek:
Since I'm calling it against the namespace (not a mapi folder) it must search the whole structure - otherwise it wouldn't make sense. That's a really elegant solution RobDogg, thanks.
Re: Can you 'find' a contact from code in outlook
Bah, I knew it was too good to be true. :cry:
I can't use entryID because it's read only and auto assigned by outlook when the item is created so that idea's :duck:ed. I considered keeping a table in the db that paired outlook entryID with the db reference but I've read that the entryID changes if you move the item between folders in outlook so that won't work either.
Any more ideas folks?
p.s. I've always wanted to use the duck ;)
Re: Can you 'find' a contact from code in outlook
The .EntryID is read only because its the serial number of the item in Outlook in a particular Mailbox or Store (pst file). It does
not change if you move it between folders. Once an item is created and saved the .EntryID is generated and will stay with the
item for as long as it exists in Outlook.
Maybe I dont understand how you need to use it? If you have the ContactItem in Outlook and you want to also save it to Access then it
will have the .EntryID. If the item is in Access and not Outlook yet, then save it to Outlook and retrieve the .EntryID property for saving
back to the Access db so you can find it later.
Re: Can you 'find' a contact from code in outlook
I'm bringing contacts from a crm database into outlook rather than pushing contacts from outlook into a database. I wanted to store the reference from teh crm database against the contact in outlook so that, if the contact is changed in the crm database, I can find it again in outlook and update it.
I must have missunderstood what I read about the entryID changing. I assume this must have been if you move it between stores. If it doesn't change within the same store I can just maintain a table in the crm database which matches the db reference against the outlook entryID. Thanks
Re: Can you 'find' a contact from code in outlook - Resolved
That is correct. Only when moved between stores will it change.
This should make you feel better:
http://msdn.microsoft.com/library/de...HV05247424.asp
:)