How to use Access Table instead of Outlook Address Book?

D

deko

I have an Access 2003 table that holds all my contacts/email addresses - is
there a way to get Outlook to use this instead of the standard Address Book
or Contacts folder? For example, when I go to Tools >> Address Book from my
Outlook Inbox, is there a way to get my Access database/Table in the "Show
Names from..." drop down list? Or do I have to make a separate PST and
import all the data from Access?
 
D

deko

Public Sub syncContacts()
On Error GoTo HandleErr
Dim rst As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim cf As Outlook.MAPIFolder
Dim ol As New Outlook.Application
Dim oci As Outlook.ContactItem
Dim olns As Outlook.Namespace
Set objOutlook = CreateObject("Outlook.Application")
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
Do Until cf.Items.Count = 0
For Each oci In cf.Items
oci.Delete
Next oci
Loop
Set rst = CurrentDb.OpenRecordset("qryContacts")
Do Until rst.EOF
Set oci = objOutlook.CreateItem(olContactItem)
With oci
.Title = rst!Prefix
.FirstName = rst!FirstName
.MiddleName = rst!MiddleName
.LastName = rst!LastName
.Suffix = rst!Suffix
.CompanyName = rst!Company
.Email1Address = rst!EmailAddress
.Body = "Entity ID " & rst!Entity_ID
.Close (olSave)
End With
rst.MoveNext
Loop
Exit_Here:
Set olns = Nothing
Set cf = Nothing
Set rst = Nothing
Set objOutlook = Nothing
Exit Sub
HandleErr:
Select Case Err.Number
Case 94 'Invalid use of null
Resume Next
Case Else
modHandler.LogErr ("modOutlook(syncContacts)")
Resume Exit_Here
End Select
End Sub
 

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