How do I reference a public folder in VBA?

D

Dave F

I am trying to export custom fields from Outlook 2003 using Access 2003 and
VBA (see full code below).

How can I reference a specific public folder in VBA?

I can reference my personal outlook folder as:
Set cf = olns.GetDefaultFolder(olFolderContacts)

This works fine. But I need to access a public folder.

I can change the setting to this:

Set cf = olns.GetDefaultFolder(olPublicFoldersAllPublicFolders)

But I get an empty result set.

How can I reference a _specific_ public folder in VBA?


Here is my full code:

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("_TestImport")

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)
rst.AddNew
'standard properties
rst![Company] = c.CompanyName
'custom properties
'rst!ISP = c.UserProperties("ISP")
rst.Update
End If
Next i
rst.Close
 
D

Dave F

Thanks

Good example.



Sue Mosher said:
To get a non-default folder, 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
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Dave F said:
I am trying to export custom fields from Outlook 2003 using Access 2003 and
VBA (see full code below).

How can I reference a specific public folder in VBA?

I can reference my personal outlook folder as:
Set cf = olns.GetDefaultFolder(olFolderContacts)

This works fine. But I need to access a public folder.

I can change the setting to this:

Set cf = olns.GetDefaultFolder(olPublicFoldersAllPublicFolders)

But I get an empty result set.

How can I reference a _specific_ public folder in VBA?


Here is my full code:

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("_TestImport")

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)
rst.AddNew
'standard properties
rst![Company] = c.CompanyName
'custom properties
'rst!ISP = c.UserProperties("ISP")
rst.Update
End If
Next i
rst.Close
 

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