How to open Public Folders 'Contact Form' using VBA

G

Guest

I am using Access 2003, Outlook 2003, Exchange 2003

I am developing a simple Access CRM for our office. The DB uses a linked
connection to Outlook/Public Folders/Address Book to populate the contacts
table.

To create new contacts, it seems easiest to simply open a new contact form
to add the new contact. When I use the following code, it opens a new contact
form for my personal contacts folder. I need it to open a new contact form
for the Public Folders Address book. Here is the code I am using now:

Sub StartOutLook_click()
On Error GoTo StartOutLook_Error
Dim spObj As Object, MyItem As Object

' Create a Microsoft OutLook object.
Set spObj = CreateObject("Outlook.Application")

' Create and open new contact form for input.
Set MyItem = spObj.CreateItem(olContactItem)
MyItem.Display

' Quit Microsoft Outlook.
Set spObj = Nothing
Exit Sub

StartOutLook_Error:
MsgBox "Error: " & Err & " " & Error
Exit Sub
End Sub

**************************
I have also tried this code where I have gotten the ID for the Address Book
I want to use:
**************************

Private Sub PubFolderContact()
Dim olfolder As Outlook.mapiFolder
Dim olapp As Outlook.Application
Dim MyItem As Object
Set olapp = CreateObject("Outlook.Application")
Set olfolder = olapp.GetNamespace("Mapi").GetFolderFromID("000000
001A447390AA6611CD9BC800AA002FC45A030082A9113B53F5
E344B7226F2A7489F43100000009A8BD0000")
Set MyItem = olapp.CreateItem(olContactItem)
MyItem.Display

Set olfolder = Nothing
Set olapp = Nothing
End Sub

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

This code also only opens the Personal Contacts form. Please advise on how
to open a Public Folders/Address Book contact form.
 
S

Sue Mosher [MVP-Outlook]

To create a new instance of a custom form programmatically, use the Add method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Post.YourFormName")

You can use the code at http://www.outlookcode.com/d/code/getfolder.htm to walk the folder hierarchy and return the MAPIFolder corresponding to a given path string.

--
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