Link to Outlook Contacts - Add Fields (1 Viewer)

Tskutnik

Registered User.
Local time
Today, 12:01
Joined
Sep 15, 2012
Messages
229
All,
Hope this finds you well.

I have a DB linked to Outlook contacts, but not all of the Contact fields are being pulled in. Anyone know how to change the Outlook fields being pushed/pulled?

There is a decent Contacts DB template, but the interaction with Outlook is not linked, so the data is pushed/pulled in batch and there are dupes all over the place.
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:01
Joined
Jan 23, 2006
Messages
15,364
Check the Similar Threads at the bottom of this page.
 

Joe Boatman

New member
Local time
Today, 16:01
Joined
May 30, 2020
Messages
25
I hope that this will help you. The names of the fields that Outlook uses are different to the column headings in the People (Contacts) section of Outlook 2016. Paste the following code into a new module and step though it with the Locals window open and open the oContact section to see all the field names.

Simplest method of getting contacts from Outlook using VBA

Code:
Option Compare Database
Option Explicit

'29 May 2020
'Simplest method of getting contacts from Outlook. See apContactFetchFromOutlook for comprehensive method
'Requires no references or support functions!
'Press F8 to step through this code and View (menu) Locals window
Private Sub apGetContactFromOutlook()

    Dim sName As String, sEmail As String, sCompany As String, sPhone As String, sMobile As String
    Dim nRetVal As Integer
    Dim olApp As Object, oNameSpace As Object, oContactFolder As Object, oContact As Object
    Const olFolderContacts As Long = 10
    Const olContact As Long = 40

On Error Resume Next

    Set olApp = VBA.GetObject(, "Outlook.Application")  'Assumes Outlook is open else err 429
    Err.Clear
    If olApp Is Nothing Then GoTo ExitRoutine   'Outlook needs to be open!

    Set oNameSpace = olApp.GetNamespace("MAPI")
    Set oContactFolder = oNameSpace.GetDefaultFolder(olFolderContacts)
    nRetVal = oContactFolder.Items.Count
    If nRetVal = 0 Then GoTo ExitRoutine    'No contacts

    For Each oContact In oContactFolder.Items
        With oContact
            sName = .FullName
            sEmail = .Email1Address
            sCompany = .CompanyName 'To see all members, see Locals window while stepping through code!
            sPhone = .BusinessTelephoneNumber
            sMobile = .MobileTelephoneNumber
        End With
    Next

    Set oContact = Nothing
    Set oContactFolder = Nothing
    Set oNameSpace = Nothing
    Set olApp = Nothing

ExitRoutine:
End Sub
 

Tskutnik

Registered User.
Local time
Today, 12:01
Joined
Sep 15, 2012
Messages
229
Thanks very much Joe. I will try this a bit later today.
Does this code keep Outlook and Access in sync real time (both ways) or is it more of a batch pull and load of data?
 

Joe Boatman

New member
Local time
Today, 16:01
Joined
May 30, 2020
Messages
25
Do you want to keep them in synch? I've always used a database to keep contacts and if I want to email a contact, I click a link which opens a new message in Outlook.
 

Tskutnik

Registered User.
Local time
Today, 12:01
Joined
Sep 15, 2012
Messages
229
Id prefer they were in sync so Outlook and our phones have all the up to date data. Im trying to use Access as a CRM. Some of their tools and DB's are good but I need some tweaks.
 

Joe Boatman

New member
Local time
Today, 16:01
Joined
May 30, 2020
Messages
25
Sounds interesting! The code I published simply pulls contacts out of Outlook and into a table in Access.

Can you elaborate on the phones bit? Do the phones use Outlook as the email client? And how does DRM info on Access currently get to Outlook and/or phones?
 

Tskutnik

Registered User.
Local time
Today, 12:01
Joined
Sep 15, 2012
Messages
229
We have the normal Outlook/Cellphone syncs facilitated by our network. In Access' link to Database you can link directly to OL contacts and the sync is real time, if you update from Access or from outlook. the outlook to phones is through the email client.
 

Joe Boatman

New member
Local time
Today, 16:01
Joined
May 30, 2020
Messages
25
Useful. So what are you looking for? I can send you my Outlook code as an accdb file and you can step through the code for learning purposes...
 

Tskutnik

Registered User.
Local time
Today, 12:01
Joined
Sep 15, 2012
Messages
229
I need to add fields to the linked database function. The interface does not send all of the outlook contact fields to Access, e.g. Home Phone and Notes.
If your code is more of a batch process it may not work for what I need, but obviously I would take a a look.
Really appreciate the help.
 

Joe Boatman

New member
Local time
Today, 16:01
Joined
May 30, 2020
Messages
25
Hi Tskutnik. Attached is the code that I hope will help. In modOutlook you will find apGetContactFromOutlook() which looks at various fields in Outlook's contacts. Stop at the line "sName = .FullName" and view the Locals window to see all the field names in the oContact section. You will find HomeTelephoneNumber, Home2TelephoneNumber and Body (that's the Notes field).
apContactFetchFromOutlook is a better routine for putting Outlook fields into a table and you will also find modFunctions.apFieldAdd() to put the new table field names into the back end database, unless you can do this manually.
 

Attachments

  • Get Outlook Contacts.accdb
    656 KB · Views: 107

Users who are viewing this thread

Top Bottom