Looking for Code to link an Outlook Address Book

S

shanej2015

Hello,

I'm looking for code that will link an Outlook Address Book to my
database. I want to use code so that it will check and link to the
address book everytime the db is open, if the link is not there it will
add it.

Shane
 
B

Brian

File -> Get External Data -> Link Tables. Pick Files of Type -> Exchange (or
Outlook as appropriate)
 
B

Brian

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.
 

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