Referring to Items in Public (Contacts) Folder 
Author Message
 Referring to Items in Public (Contacts) Folder

The following code works in VB 6.0 without a problem:

***********************************************************
Private Sub cmdAdressen_Click()
    Set objOLApp = CreateObject("Outlook.Application")
    Set objNamespace = objOLApp.GetNamespace("MAPI")

    Set objContactsFolder = objNamespace.GetDefaultFolder(olFolderContacts)
    Set objContactItem = objContactsFolder.Items.GetFirst()

    MsgBox objContactItem.CompanyName
End Sub
***********************************************************

When I try the same thing with a Public Folder with ContactItems, I type:

***********************************************************
Const PR_IPM_PUBLIC_FOLDERS_ENTRYID = &H66310102
Private Sub cmdAdressen2_Click()
    Set objOLApp = CreateObject("Outlook.Application")
    Set objNamespace = objOLApp.GetNamespace("MAPI")

    Set objSession = CreateObject("MAPI.Session")
    If Not objSession Is Nothing Then
        objSession.Logon NewSession:=False
    End If

' Get the 'Public Folders' (In Dutch)
    Set objInfoStore = objSession.InfoStores("Openbare mappen")

' Get the root
    strPublicRootId =
objInfoStore.Fields.Item(PR_IPM_PUBLIC_FOLDERS_ENTRYID).Value

' Get 'All Public Folders' (Topmap in the Root)
    Set objTopFolder = objSession.GetFolder(strPublicRootId,
objInfoStore.ID)

' Maps in 'All Public Folders'
    Set objFolders = objTopFolder.Folders

' Get the Contacts Folder in the Public Folders
    Set objContactsFolder = objFolders.Item("Adressen")

''''''''''''''''''''''''''''''''' HERE IT GOES WRONG
    Set objContactItem = objContactsFolder.Items.GetFirst()

    MsgBox objContactItem.CompanyName
End Sub
***********************************************************

I get an error  'Object doesn't support this property or method'. It seems
that the folder is not recognized as a folder with Contact Items.

I can type:

Set objContactItem = objContactsFolder.Messages.GetFirst()

But of course then the following line (MsgBox objContactItem.CompanyName)
gives the same error

What am I doing wrong???

Marc



Sat, 03 Jan 2004 23:56:29 GMT  
 Referring to Items in Public (Contacts) Folder
You need to get the contacts as Message items. Then you need to use
property tags to get the contact properties. See
http://www.cdolive.com/cdo10.htm for the property tags to use, and
http://www.cdolive.com/cdo5.htm for some code samples dealing with
contacts and CDO.

--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams



Quote:
> The following code works in VB 6.0 without a problem:

> ***********************************************************
> Private Sub cmdAdressen_Click()
>     Set objOLApp = CreateObject("Outlook.Application")
>     Set objNamespace = objOLApp.GetNamespace("MAPI")

>     Set objContactsFolder =

objNamespace.GetDefaultFolder(olFolderContacts)
Quote:
>     Set objContactItem = objContactsFolder.Items.GetFirst()

>     MsgBox objContactItem.CompanyName
> End Sub
> ***********************************************************

> When I try the same thing with a Public Folder with ContactItems, I
type:

> ***********************************************************
> Const PR_IPM_PUBLIC_FOLDERS_ENTRYID = &H66310102
> Private Sub cmdAdressen2_Click()
>     Set objOLApp = CreateObject("Outlook.Application")
>     Set objNamespace = objOLApp.GetNamespace("MAPI")

>     Set objSession = CreateObject("MAPI.Session")
>     If Not objSession Is Nothing Then
>         objSession.Logon NewSession:=False
>     End If

> ' Get the 'Public Folders' (In Dutch)
>     Set objInfoStore = objSession.InfoStores("Openbare mappen")

> ' Get the root
>     strPublicRootId =
> objInfoStore.Fields.Item(PR_IPM_PUBLIC_FOLDERS_ENTRYID).Value

> ' Get 'All Public Folders' (Topmap in the Root)
>     Set objTopFolder = objSession.GetFolder(strPublicRootId,
> objInfoStore.ID)

> ' Maps in 'All Public Folders'
>     Set objFolders = objTopFolder.Folders

> ' Get the Contacts Folder in the Public Folders
>     Set objContactsFolder = objFolders.Item("Adressen")

> ''''''''''''''''''''''''''''''''' HERE IT GOES WRONG
>     Set objContactItem = objContactsFolder.Items.GetFirst()

>     MsgBox objContactItem.CompanyName
> End Sub
> ***********************************************************

> I get an error  'Object doesn't support this property or method'. It
seems
> that the folder is not recognized as a folder with Contact Items.

> I can type:

> Set objContactItem = objContactsFolder.Messages.GetFirst()

> But of course then the following line (MsgBox

objContactItem.CompanyName)

- Show quoted text -

Quote:
> gives the same error

> What am I doing wrong???

> Marc



Sun, 04 Jan 2004 01:48:39 GMT  
 Referring to Items in Public (Contacts) Folder
I tried the following:

(...)
    Set objContactItem = objContactsFolder.Messages.GetFirst()

    'Get the fields collection of the contact item
    Set objFields = objContactItem.Fields

    Value = objFields.Item("{0420060000000000C000000000000046}0x801A").Value

But I always get an error: MAPI_E_NOT_FOUND(8004010F)

I tried with other values, but none seems to work...

Marc



Quote:
> You need to get the contacts as Message items. Then you need to use
> property tags to get the contact properties. See
> http://www.cdolive.com/cdo10.htm for the property tags to use, and
> http://www.cdolive.com/cdo5.htm for some code samples dealing with
> contacts and CDO.

> --
> Ken Slovak
> [MVP - Outlook]
> Lead Author, Professional Outlook 2000 Programming, Wrox Press
> Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
> Appendices, Sams



> > The following code works in VB 6.0 without a problem:

> > ***********************************************************
> > Private Sub cmdAdressen_Click()
> >     Set objOLApp = CreateObject("Outlook.Application")
> >     Set objNamespace = objOLApp.GetNamespace("MAPI")

> >     Set objContactsFolder =
> objNamespace.GetDefaultFolder(olFolderContacts)
> >     Set objContactItem = objContactsFolder.Items.GetFirst()

> >     MsgBox objContactItem.CompanyName
> > End Sub
> > ***********************************************************

> > When I try the same thing with a Public Folder with ContactItems, I
> type:

> > ***********************************************************
> > Const PR_IPM_PUBLIC_FOLDERS_ENTRYID = &H66310102
> > Private Sub cmdAdressen2_Click()
> >     Set objOLApp = CreateObject("Outlook.Application")
> >     Set objNamespace = objOLApp.GetNamespace("MAPI")

> >     Set objSession = CreateObject("MAPI.Session")
> >     If Not objSession Is Nothing Then
> >         objSession.Logon NewSession:=False
> >     End If

> > ' Get the 'Public Folders' (In Dutch)
> >     Set objInfoStore = objSession.InfoStores("Openbare mappen")

> > ' Get the root
> >     strPublicRootId =
> > objInfoStore.Fields.Item(PR_IPM_PUBLIC_FOLDERS_ENTRYID).Value

> > ' Get 'All Public Folders' (Topmap in the Root)
> >     Set objTopFolder = objSession.GetFolder(strPublicRootId,
> > objInfoStore.ID)

> > ' Maps in 'All Public Folders'
> >     Set objFolders = objTopFolder.Folders

> > ' Get the Contacts Folder in the Public Folders
> >     Set objContactsFolder = objFolders.Item("Adressen")

> > ''''''''''''''''''''''''''''''''' HERE IT GOES WRONG
> >     Set objContactItem = objContactsFolder.Items.GetFirst()

> >     MsgBox objContactItem.CompanyName
> > End Sub
> > ***********************************************************

> > I get an error  'Object doesn't support this property or method'. It
> seems
> > that the folder is not recognized as a folder with Contact Items.

> > I can type:

> > Set objContactItem = objContactsFolder.Messages.GetFirst()

> > But of course then the following line (MsgBox
> objContactItem.CompanyName)
> > gives the same error

> > What am I doing wrong???

> > Marc



Sun, 04 Jan 2004 04:27:29 GMT  
 Referring to Items in Public (Contacts) Folder
If an item doesn't have a value for a field that error will result.
Also, if you have any distribution lists in your folder you have to
make sure you aren't getting one of those. Does that first contact
item have an entry in the HomeAddress field?

I'd try with a field that you know exists and has values and see what
happens. It does work, I've used those property tags many times with
Outlook contact items.

--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams



Quote:
> I tried the following:

> (...)
>     Set objContactItem = objContactsFolder.Messages.GetFirst()

>     'Get the fields collection of the contact item
>     Set objFields = objContactItem.Fields

>     Value =

objFields.Item("{0420060000000000C000000000000046}0x801A").Value
Quote:

> But I always get an error: MAPI_E_NOT_FOUND(8004010F)

> I tried with other values, but none seems to work...

> Marc



Sun, 04 Jan 2004 04:43:42 GMT  
 Referring to Items in Public (Contacts) Folder
You're right, it worked... almost.

I need the categories in the item, so I tried this:

****************************************************************************
****
Const CdoContact_Categories = "{2903020000000000C000000000000046}Keywords"
Const CdoPR_COMPANY_NAME = &H3A16001F

Set MyMessages = objContactsFolder.Messages

For Each objContactItem In MyMessages

        Set objFields = objContactItem.Fields

        Set objField1 = Nothing
        Set objField2 = Nothing

        On Error Resume Next
        Set objField1 = objFields.Item(CdoContact_Categories)
        Waarde1 = objField1.Value
        If Waarde1 = Empty Then
            Waarde1 = ""
        End If

        Set objField2 = objFields.Item(CdoPR_COMPANY_NAME)
        Waarde2 = objField2.Value
        MsgBox "Waarde = " + Waarde2 + " " + Waarde1

    Next

*******************************************************

No problem for the CompanyName, but the Categoriesfield is always empty...

Marc



Quote:
> If an item doesn't have a value for a field that error will result.
> Also, if you have any distribution lists in your folder you have to
> make sure you aren't getting one of those. Does that first contact
> item have an entry in the HomeAddress field?

> I'd try with a field that you know exists and has values and see what
> happens. It does work, I've used those property tags many times with
> Outlook contact items.

> --
> Ken Slovak
> [MVP - Outlook]
> Lead Author, Professional Outlook 2000 Programming, Wrox Press
> Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
> Appendices, Sams



> > I tried the following:

> > (...)
> >     Set objContactItem = objContactsFolder.Messages.GetFirst()

> >     'Get the fields collection of the contact item
> >     Set objFields = objContactItem.Fields

> >     Value =
> objFields.Item("{0420060000000000C000000000000046}0x801A").Value

> > But I always get an error: MAPI_E_NOT_FOUND(8004010F)

> > I tried with other values, but none seems to work...

> > Marc



Sun, 04 Jan 2004 15:39:35 GMT  
 Referring to Items in Public (Contacts) Folder
Categories, or any of the keyword type fields are written or read as a
variant array. Here is code that will read the Categories field of a
currently open contact item that has entries in the Categories field.
The open contact should be in the ActiveInspector window:

Private Sub ReadCategories()
  Dim oApp As Outlook.Application
  Dim oContact As Outlook.ContactItem
  Dim sID As String
  Dim oCDO As MAPI.Session
  Dim oMsg As MAPI.Message
  Dim oFields As MAPI.Fields
  Dim oField As MAPI.Field
  Dim vCategories As Variant
  Dim asCategories() As String
  Dim i As Long

  Const CdoPropSetID5 = "2903020000000000C000000000000046"
  Const CdoContact_Categories = "{" & CdoPropSetID5 _
    & "}" & "Keywords"

  Set oApp = CreateObject("Outlook.Application")
  Set oContact = oApp.ActiveInspector.CurrentItem
  sID = oContact.EntryID

  Set oCDO = CreateObject("MAPI.Session")
  oCDO.Logon "", "", False, False
  Set oMsg = oCDO.GetMessage(sID)

  Set oFields = oMsg.Fields
  Set oField = oFields.Item(CdoContact_Categories)
  vCategories = oFields.Item(CdoContact_Categories).Value

  i = UBound(vCategories)
  ReDim asCategories(i)
  For i = LBound(vCategories) To UBound(vCategories)
    asCategories(i) = vCategories(i)
  Next

  oCDO.Logoff

  Set oMsg = Nothing
  Set oFields = Nothing
  Set oField = Nothing
  Set oCDO = Nothing

  Set oApp = Nothing
  Set oContact = Nothing
End Sub

My thanks to Sig Weber of CDOLive for verifying this method of working
with Keywords fields.

--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams



Quote:
> You're right, it worked... almost.

> I need the categories in the item, so I tried this:

**********************************************************************
******
Quote:
> ****
> Const CdoContact_Categories =

"{2903020000000000C000000000000046}Keywords"
Quote:
> Const CdoPR_COMPANY_NAME = &H3A16001F

> Set MyMessages = objContactsFolder.Messages

> For Each objContactItem In MyMessages

>         Set objFields = objContactItem.Fields

>         Set objField1 = Nothing
>         Set objField2 = Nothing

>         On Error Resume Next
>         Set objField1 = objFields.Item(CdoContact_Categories)
>         Waarde1 = objField1.Value
>         If Waarde1 = Empty Then
>             Waarde1 = ""
>         End If

>         Set objField2 = objFields.Item(CdoPR_COMPANY_NAME)
>         Waarde2 = objField2.Value
>         MsgBox "Waarde = " + Waarde2 + " " + Waarde1

>     Next

> *******************************************************

> No problem for the CompanyName, but the Categoriesfield is always
empty...

> Marc



Sun, 04 Jan 2004 21:47:34 GMT  
 Referring to Items in Public (Contacts) Folder
Thanks a lot for this answer.

Btw, I ordered your book "Professional Outlook 2000 Programming"

You more then convinced me you know what you're talking about :-)

Marc



Quote:
> Categories, or any of the keyword type fields are written or read as a
> variant array. Here is code that will read the Categories field of a
> currently open contact item that has entries in the Categories field.
> The open contact should be in the ActiveInspector window:

> Private Sub ReadCategories()
>   Dim oApp As Outlook.Application
>   Dim oContact As Outlook.ContactItem
>   Dim sID As String
>   Dim oCDO As MAPI.Session
>   Dim oMsg As MAPI.Message
>   Dim oFields As MAPI.Fields
>   Dim oField As MAPI.Field
>   Dim vCategories As Variant
>   Dim asCategories() As String
>   Dim i As Long

>   Const CdoPropSetID5 = "2903020000000000C000000000000046"
>   Const CdoContact_Categories = "{" & CdoPropSetID5 _
>     & "}" & "Keywords"

>   Set oApp = CreateObject("Outlook.Application")
>   Set oContact = oApp.ActiveInspector.CurrentItem
>   sID = oContact.EntryID

>   Set oCDO = CreateObject("MAPI.Session")
>   oCDO.Logon "", "", False, False
>   Set oMsg = oCDO.GetMessage(sID)

>   Set oFields = oMsg.Fields
>   Set oField = oFields.Item(CdoContact_Categories)
>   vCategories = oFields.Item(CdoContact_Categories).Value

>   i = UBound(vCategories)
>   ReDim asCategories(i)
>   For i = LBound(vCategories) To UBound(vCategories)
>     asCategories(i) = vCategories(i)
>   Next

>   oCDO.Logoff

>   Set oMsg = Nothing
>   Set oFields = Nothing
>   Set oField = Nothing
>   Set oCDO = Nothing

>   Set oApp = Nothing
>   Set oContact = Nothing
> End Sub

> My thanks to Sig Weber of CDOLive for verifying this method of working
> with Keywords fields.

> --
> Ken Slovak
> [MVP - Outlook]
> Lead Author, Professional Outlook 2000 Programming, Wrox Press
> Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
> Appendices, Sams



> > You're right, it worked... almost.

> > I need the categories in the item, so I tried this:

> **********************************************************************
> ******
> > ****
> > Const CdoContact_Categories =
> "{2903020000000000C000000000000046}Keywords"
> > Const CdoPR_COMPANY_NAME = &H3A16001F

> > Set MyMessages = objContactsFolder.Messages

> > For Each objContactItem In MyMessages

> >         Set objFields = objContactItem.Fields

> >         Set objField1 = Nothing
> >         Set objField2 = Nothing

> >         On Error Resume Next
> >         Set objField1 = objFields.Item(CdoContact_Categories)
> >         Waarde1 = objField1.Value
> >         If Waarde1 = Empty Then
> >             Waarde1 = ""
> >         End If

> >         Set objField2 = objFields.Item(CdoPR_COMPANY_NAME)
> >         Waarde2 = objField2.Value
> >         MsgBox "Waarde = " + Waarde2 + " " + Waarde1

> >     Next

> > *******************************************************

> > No problem for the CompanyName, but the Categoriesfield is always
> empty...

> > Marc



Mon, 05 Jan 2004 04:18:25 GMT  
 Referring to Items in Public (Contacts) Folder
Thanks, but I should tell you that my book has minimal coverage of
CDO. It's more Outlook object model oriented, although there is some
CDO in it. If you are interested in CDO you would do well to get
Siegfreid Weber's Professional CDO Programming book, also from Wrox.
He's the real master of CDO.

--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams



Quote:
> Thanks a lot for this answer.

> Btw, I ordered your book "Professional Outlook 2000 Programming"

> You more then convinced me you know what you're talking about :-)

> Marc



Mon, 05 Jan 2004 04:41:14 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Public Folder Contact folders.

2. Syncronize in programmatic way, the folder Contact with the public folder

3. Unread Items in Public Folders like in personal Folders

4. How do I add a contact to a public folder programatically

5. Resolve Contact to Public Folder

6. Need sample code for read public folder contact into access

7. Enable a Public folder (contacts) for Outlook address Book

8. Create New Contact in Public Folder

9. Synchronizing/exporting contacts into Public Folder

10. Creating Contacts in a Public Folder

11. Error copying a public Contact folder within Outlook 2000 SR1

12. Public Contacts Folder

 

 
Powered by phpBB® Forum Software