setting my code to access contacts from a a different folder.

G

Guest

Here is the beginning of some code I'm using:
' Set up DAO objects (uses existing "Contacts" table)
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Outlook Contacts")

' Set up Outlook objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty

Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
Set objItems = cf.Items
iNumContacts = objItems.Count
If iNumContacts <> 0 Then
For I = 1 To iNumContacts
If TypeName(objItems(I)) = "ContactItem" Then
Set c = objItems(I)
If c.Categories = strCategory Then 'It's one of the right category


My question is which part of this do I need to change if I want to access
contacts in a different folder? In Outlook, I have a folder called Work
Contacts, it's not a sub folder to "Contacts" it's just another folder in the
list where it says Contacts, Inbox, Outbox, etc... I'd like to access these
contact items directly, rather than having to always move them to my regular
Contact folder to access them.
thanks,
ck
 
S

Sue Mosher [MVP-Outlook]

To get a non-default folder, instead of GetDefaultFolder, you need to walk the folder hierarchy using the Folders collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Set objFolder = GetFolder("Public Folders/All Public Folders/Company/Sales")

Hi again. My folder "Work Contacts" is in the list with the other outlook
items, like Contacts, Calendar, Inbox, etc. I haven't made any other
folders, and when I click the properties of "Work Contacts" is says the
location is \\Personal Folders.
So should I use
Set objFolder = GetFolder("Public Folders/Personal Folders\Work Contacts")?
thanks,
ck
 
S

Sue Mosher [MVP-Outlook]

Look in the Folder List navigation pane. The path to the folder in question needs to ***exactly*** match the names of the branches in its hierarchy, just like the path to a file in the file system. Why would you include Public Folders if It's not a part of the hierarchy above Work Contacts?

Also, if you have Outlook Spy and Outlook 2002 or later, you can check the value of the FolderPath property.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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