Hmmm....sorry. I guess I missed the part about the need to dynamically open
different address books. If it is a link to a static address book, then that
would do it. If it is not, it is not as simple as establishing a link; there
are parameters that must need to be provided by the user at runtime (which
can be done via a browse window). That is, the connect string for a linked
address book or contact list looks like this:
Outlook 9.0;MAPILEVEL=Personal
Folders|;PROFILE=Outlook;TABLETYPE=0;TABLENAME=Contacts;DATABASE=C:\DOCUME~1\User\LOCALS~1\Temp\;TABLE=Contacts
You will see that the version of Outlook, the MAPI type (Personal Folders or
Address Book), Profile name, Table (Outlook folder) name are all embedded.
If you know the Outlook version, MAPI profile name, contact folder name, and
User name beforehand, it is an easy thing to update the linked table's
connect string. However, if a user opens the app on a PC having a different
version of Outlook, the Outlook 9.0 may be Outlook 8.0, or the MAPI profile
name may differ.
Thus, we need to:
1. Create the linked table once manually (can be done programmatically, but
I think this is easier done manually)
2. Test for a valid connection to the linked table when opening the app
(e.g. count the records in the linked table and anticipate the error that
will occur if the connection is not valid)
3. On Error, allow user to browse for a MAPI contact folder and then
4. Store the connect string.
Well, I had time to get part of #3 and will work on more later if I have
time and no MVP's get you a better answer in the meantime. This should at
least get you started.
Dim ol As Object 'Outlook
Dim olns As Object 'Outlook namespace
Dim cf As Object 'contacts folder
Dim c As Object
Dim Prop As Object
Set ol = CreateObject("Outlook.Application")
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.PickFolder
This gets you as far as browsing for the folder. Play around with it, and I
will see if I can extract the Outlook version, etc. from the properties of
one of the objects so that you can update the connect string.