How to extract ContactItem entry id from the AddressEntry entry id 
Author Message
 How to extract ContactItem entry id from the AddressEntry entry id

Hi There,

I'm trying to get the Contact Item EntryID from the AddressEntry
Object. I have tried all sorts of thing, but am nowhere. Any help will
be appreciated.
The code I'm using is

'cdo variables
Dim objCdoSession As MAPI.Session
Dim objAddressList As MAPI.AddressList
Dim objAddressEntries As MAPI.AddressEntries

'Outlook Variables
Dim oSession as Outlook.Application
Dim oNs as Outlook.NameSpace
Dim oContactItem as Outlook.ContactItem

Set objCdoSession = CreateObject("MAPI.Session")
objCdoSession.Logon()
Set objAddressList = objCdoSession.AddressLists.Item("Contacts")
Set objAddressEntries = objAddressList.AddressEntries

Set oSession = CreateObject("Outlook.Application")
Set oNs = oSession.GetNameSpace("MAPI")
For ctr = 1 To objAddressEntries.Count
   Set objAddressEntry = objAddressEntries.Item(ctr)
   'MY PROGRAM FAILS HERE . THIS IS WHERE I AM STUCK . HOW DO I GET
CONTACT ITEM
   'FROM THE ADDRESS ENTRY ID.
   Set oContactItem = oNs.GetItemFromId(objAddressEntry .ID)
Next



Sun, 18 Sep 2005 13:18:41 GMT  
 How to extract ContactItem entry id from the AddressEntry entry id
Is objAddressEntry is a CDO AddressEntry or an Outlook.AddressEntry
object? It's not defined anywhere.

There is no direct way to get a contact item from and AddressEntry.
The EntryID's of the items are different. You can get the name of the
AddressEntry and use that to filter the Contacts folder's Items
collection.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


Quote:
> Hi There,

> I'm trying to get the Contact Item EntryID from the AddressEntry
> Object. I have tried all sorts of thing, but am nowhere. Any help
will
> be appreciated.
> The code I'm using is

> 'cdo variables
> Dim objCdoSession As MAPI.Session
> Dim objAddressList As MAPI.AddressList
> Dim objAddressEntries As MAPI.AddressEntries

> 'Outlook Variables
> Dim oSession as Outlook.Application
> Dim oNs as Outlook.NameSpace
> Dim oContactItem as Outlook.ContactItem

> Set objCdoSession = CreateObject("MAPI.Session")
> objCdoSession.Logon()
> Set objAddressList = objCdoSession.AddressLists.Item("Contacts")
> Set objAddressEntries = objAddressList.AddressEntries

> Set oSession = CreateObject("Outlook.Application")
> Set oNs = oSession.GetNameSpace("MAPI")
> For ctr = 1 To objAddressEntries.Count
>    Set objAddressEntry = objAddressEntries.Item(ctr)
>    'MY PROGRAM FAILS HERE . THIS IS WHERE I AM STUCK . HOW DO I GET
> CONTACT ITEM
>    'FROM THE ADDRESS ENTRY ID.
>    Set oContactItem = oNs.GetItemFromId(objAddressEntry .ID)
> Next



Sun, 18 Sep 2005 22:53:14 GMT  
 How to extract ContactItem entry id from the AddressEntry entry id
objAddressEntry is a CDO AddressEntry. Say, i have the name "Mita" in
the AddressEntry, then how do i filter the contacts folder's items
collection. And also what do I do if it's a Distribution List name. I
also want to find the name and business fax number of each member in
the Distribution List.

Thanks Ken for your time.

Regards Mita


Quote:
> Is objAddressEntry is a CDO AddressEntry or an Outlook.AddressEntry
> object? It's not defined anywhere.

> There is no direct way to get a contact item from and AddressEntry.
> The EntryID's of the items are different. You can get the name of the
> AddressEntry and use that to filter the Contacts folder's Items
> collection.

> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Lead Author, Professional Outlook 2000 Programming, Wrox Press
> Lead Author, Beginning VB 6 Application Development, Wrox Press
> Attachment Options
> http://www.slovaktech.com/attachmentoptions.htm
> Extended Reminders
> http://www.slovaktech.com/extendedreminders.htm



> > Hi There,

> > I'm trying to get the Contact Item EntryID from the AddressEntry
> > Object. I have tried all sorts of thing, but am nowhere. Any help
>  will
> > be appreciated.
> > The code I'm using is

> > 'cdo variables
> > Dim objCdoSession As MAPI.Session
> > Dim objAddressList As MAPI.AddressList
> > Dim objAddressEntries As MAPI.AddressEntries

> > 'Outlook Variables
> > Dim oSession as Outlook.Application
> > Dim oNs as Outlook.NameSpace
> > Dim oContactItem as Outlook.ContactItem

> > Set objCdoSession = CreateObject("MAPI.Session")
> > objCdoSession.Logon()
> > Set objAddressList = objCdoSession.AddressLists.Item("Contacts")
> > Set objAddressEntries = objAddressList.AddressEntries

> > Set oSession = CreateObject("Outlook.Application")
> > Set oNs = oSession.GetNameSpace("MAPI")
> > For ctr = 1 To objAddressEntries.Count
> >    Set objAddressEntry = objAddressEntries.Item(ctr)
> >    'MY PROGRAM FAILS HERE . THIS IS WHERE I AM STUCK . HOW DO I GET
> > CONTACT ITEM
> >    'FROM THE ADDRESS ENTRY ID.
> >    Set oContactItem = oNs.GetItemFromId(objAddressEntry .ID)
> > Next



Mon, 19 Sep 2005 07:05:25 GMT  
 How to extract ContactItem entry id from the AddressEntry entry id
Hi Ken,

Soorry, again one more question. This is what  i Tried,

Private Sub checkNamesinContact(objAddressEntry as MAPI.AddressEntry)

Dim oOutlook as Outlook.Application
Dim oNs as Outlook.NameSpace
Dim oFolder as MAPI.Folder

Dim strName as String
strName = objAddressEntry.Name

Set oOutlook  = CreateObject("Outlook.Application")
Set oNs = oOutlook.GetNameSpace("MAPI")
Set oFolder = oNs.GetDefaultFolder("Contacts")
oItems = oFolder.Items

' THIS IS WHAT I WANT NOW.
'CHECK IF THIS NAME IS FROM  THE CONTACT ITEM OR FROM THE
DL(DISTRIBUTION LIST)
'IF CONTACT ITEM THEN PRINT NAME, COMPANY AND BUSINESS FAX NUMBER
'IF DL ITEM THEN  PRINT NAME, COMPANY AND BUSINESS FAX NUMBER OF EACH
MEMEBER OF THE DL
End Sub

Any help will be really appreciated


Quote:
> Is objAddressEntry is a CDO AddressEntry or an Outlook.AddressEntry
> object? It's not defined anywhere.

> There is no direct way to get a contact item from and AddressEntry.
> The EntryID's of the items are different. You can get the name of the
> AddressEntry and use that to filter the Contacts folder's Items
> collection.

> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Lead Author, Professional Outlook 2000 Programming, Wrox Press
> Lead Author, Beginning VB 6 Application Development, Wrox Press
> Attachment Options
> http://www.slovaktech.com/attachmentoptions.htm
> Extended Reminders
> http://www.slovaktech.com/extendedreminders.htm



> > Hi There,

> > I'm trying to get the Contact Item EntryID from the AddressEntry
> > Object. I have tried all sorts of thing, but am nowhere. Any help
>  will
> > be appreciated.
> > The code I'm using is

> > 'cdo variables
> > Dim objCdoSession As MAPI.Session
> > Dim objAddressList As MAPI.AddressList
> > Dim objAddressEntries As MAPI.AddressEntries

> > 'Outlook Variables
> > Dim oSession as Outlook.Application
> > Dim oNs as Outlook.NameSpace
> > Dim oContactItem as Outlook.ContactItem

> > Set objCdoSession = CreateObject("MAPI.Session")
> > objCdoSession.Logon()
> > Set objAddressList = objCdoSession.AddressLists.Item("Contacts")
> > Set objAddressEntries = objAddressList.AddressEntries

> > Set oSession = CreateObject("Outlook.Application")
> > Set oNs = oSession.GetNameSpace("MAPI")
> > For ctr = 1 To objAddressEntries.Count
> >    Set objAddressEntry = objAddressEntries.Item(ctr)
> >    'MY PROGRAM FAILS HERE . THIS IS WHERE I AM STUCK . HOW DO I GET
> > CONTACT ITEM
> >    'FROM THE ADDRESS ENTRY ID.
> >    Set oContactItem = oNs.GetItemFromId(objAddressEntry .ID)
> > Next



Mon, 19 Sep 2005 08:33:42 GMT  
 How to extract ContactItem entry id from the AddressEntry entry id
Try this:

Private Sub checkNamesinContact(objAddressEntry as MAPI.AddressEntry)

Dim oOutlook as Outlook.Application
Dim oNs as Outlook.NameSpace
Dim oFolder as MAPI.Folder
Dim oItems As Outlook.Items
Dim oFilter As Outlook.Items

Dim strName as String
strName = objAddressEntry.Name

Set oOutlook  = CreateObject("Outlook.Application")
Set oNs = oOutlook.GetNameSpace("MAPI")
Set oFolder = oNs.GetDefaultFolder("Contacts")
Set oItems = oFolder.Items
Set oFilter = oItems.Restrict("[FullName] ='" & strName & "'")
'there are single quotes after = and at the end of the string
'oFilter will now contain items that have FullName = strName
'you can get the properties you want from each item.

End Sub

You won't be able to directly get DL member names using any sort of
filter like that. You would have to get every DistributionList object
in the folder and iterate its Members collection using MemberCount and
the GetMember method.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


Quote:
> Hi Ken,

> Soorry, again one more question. This is what  i Tried,

> Private Sub checkNamesinContact(objAddressEntry as
MAPI.AddressEntry)

> Dim oOutlook as Outlook.Application
> Dim oNs as Outlook.NameSpace
> Dim oFolder as MAPI.Folder

> Dim strName as String
> strName = objAddressEntry.Name

> Set oOutlook  = CreateObject("Outlook.Application")
> Set oNs = oOutlook.GetNameSpace("MAPI")
> Set oFolder = oNs.GetDefaultFolder("Contacts")
> oItems = oFolder.Items

> ' THIS IS WHAT I WANT NOW.
> 'CHECK IF THIS NAME IS FROM  THE CONTACT ITEM OR FROM THE
> DL(DISTRIBUTION LIST)
> 'IF CONTACT ITEM THEN PRINT NAME, COMPANY AND BUSINESS FAX NUMBER
> 'IF DL ITEM THEN  PRINT NAME, COMPANY AND BUSINESS FAX NUMBER OF
EACH
> MEMEBER OF THE DL
> End Sub

> Any help will be really appreciated



Mon, 19 Sep 2005 22:52:29 GMT  
 How to extract ContactItem entry id from the AddressEntry entry id
Thanks Ken, this is what i tried and it's works fine for me now.

'Cdo variables
Dim objCdoSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objAddressList As MAPI.AddressList
Dim objAddressEntries As MAPI.AddressEntries
Dim objAddressEntry As MAPI.AddressEntry
Dim objAddressEntryMember As MAPI.AddressEntry

'Outlook Variables
Dim oSession As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
Dim oItems As Outlook.Items
Dim oContactItem As Outlook.ContactItem

Private Sub btnContacts_Click()

'Cdo Session
Set objCdoSession = CreateObject("MAPI.Session")
objCdoSession.Logon()

'Outlook Session
Set oSession = CreateObject("Outlook.Application")
Set oNs = oSession.GetNamespace("MAPI")

Set objFolder = objCdoSession.Inbox
Set objAddressList = objCdoSession.AddressLists.Item("Contacts")
Set objAddressEntries = objAddressList.AddressEntries
  For ctr = 1 To objAddressEntries.Count
      Set objAddressEntry = objAddressEntries.Item(ctr)
      checkNamesinContact(objAddressEntry)
  Next
End Sub

Private Sub checkNamesinContact(ByVal objAddressEntry As MAPI.AddressEntry)
Dim strName as String
Dim oContactType As Object

Set oFolder = oNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
Set oItems = oFolder.Items
'1 is oDistList and 5  is Private Distribution List
If (objAddressEntry.DisplayType = 1 Or objAddressEntry.DisplayType = 5) Then
  For Each objAddressEntryMember In objAddressEntry.Members
     '&H3A06001E is Cdo_PR_DISPLAY_NAME)
     strName = objAddressEntryMember.Fields(&H3A06001E).Value
     Set oContactType = oItems.Find("[FirstName] = """ & strName & """")
     If (oContactType.Class = 40) Then 'Contacts class
        Set oContactItem = oContactType
        MsgBox("BusinessTelephoneNumber   " & _
                oContactItem.BusinessTelephoneNumber)
        MsgBox("oContactItem.PagerNumber  " & oContactItem.OtherFaxNumber)
     End If
  Next
Else
  strName = objAddressEntry.Fields(&H3A06001E).Value
  oContactType = oItems.Find("[FirstName] = """ & strName & """")
  If (oContactType.Class = 40) Then
     Set oContactItem = oContactType
     MsgBox("BusinessTelephoneNumber   " & _
                oContactItem.BusinessTelephoneNumber)
     MsgBox("oContactItem.PagerNumber  " & oContactItem.OtherFaxNumber)
  end if
endif
End Sub


Quote:
> Try this:

> Private Sub checkNamesinContact(objAddressEntry as MAPI.AddressEntry)

> Dim oOutlook as Outlook.Application
> Dim oNs as Outlook.NameSpace
> Dim oFolder as MAPI.Folder
> Dim oItems As Outlook.Items
> Dim oFilter As Outlook.Items

> Dim strName as String
> strName = objAddressEntry.Name

> Set oOutlook  = CreateObject("Outlook.Application")
> Set oNs = oOutlook.GetNameSpace("MAPI")
> Set oFolder = oNs.GetDefaultFolder("Contacts")
> Set oItems = oFolder.Items
> Set oFilter = oItems.Restrict("[FullName] ='" & strName & "'")
> 'there are single quotes after = and at the end of the string
> 'oFilter will now contain items that have FullName = strName
> 'you can get the properties you want from each item.

> End Sub

> You won't be able to directly get DL member names using any sort of
> filter like that. You would have to get every DistributionList object
> in the folder and iterate its Members collection using MemberCount and
> the GetMember method.

> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Lead Author, Professional Outlook 2000 Programming, Wrox Press
> Lead Author, Beginning VB 6 Application Development, Wrox Press
> Attachment Options
> http://www.slovaktech.com/attachmentoptions.htm
> Extended Reminders
> http://www.slovaktech.com/extendedreminders.htm



> > Hi Ken,

> > Soorry, again one more question. This is what  i Tried,

> > Private Sub checkNamesinContact(objAddressEntry as
>  MAPI.AddressEntry)

> > Dim oOutlook as Outlook.Application
> > Dim oNs as Outlook.NameSpace
> > Dim oFolder as MAPI.Folder

> > Dim strName as String
> > strName = objAddressEntry.Name

> > Set oOutlook  = CreateObject("Outlook.Application")
> > Set oNs = oOutlook.GetNameSpace("MAPI")
> > Set oFolder = oNs.GetDefaultFolder("Contacts")
> > oItems = oFolder.Items

> > ' THIS IS WHAT I WANT NOW.
> > 'CHECK IF THIS NAME IS FROM  THE CONTACT ITEM OR FROM THE
> > DL(DISTRIBUTION LIST)
> > 'IF CONTACT ITEM THEN PRINT NAME, COMPANY AND BUSINESS FAX NUMBER
> > 'IF DL ITEM THEN  PRINT NAME, COMPANY AND BUSINESS FAX NUMBER OF
>  EACH
> > MEMEBER OF THE DL
> > End Sub

> > Any help will be really appreciated



Fri, 23 Sep 2005 07:50:01 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Max Size of store and entry id

2. Entry ID

3. Find Appointment item by Entry ID

4. Entry ID

5. Wrong Entry ID

6. Compare Entry ID

7. Unique entry IDs

8. Passing an Entry ID from VBScript to a C++ COM object

9. More info Entry ID

10. Entry Id

11. Maximum Entry ID Length?

12. Looking up system messages from id in event log entries

 

 
Powered by phpBB® Forum Software