You can use the following lines to export to the default local Contacts folder, or a hard-coded
folder of your choice. To use the default Contacts folder, just remove the apostrophe at the begin-
ning of the next line (this is called uncommentinga line of code, because the apostrophe in front of
the line turns it into a comment); to use a hard-coded custom folder, enter its name.
‘Set fldContacts = nms.GetDefaultFolder(olFolderContacts)
‘GoTo UpdateContacts
Use the following section of code to allow selection of a custom Contacts folder from the Folder
Picker dialog:
SelectContactFolder:
On Error Resume Next
Set fldContacts = nms.PickFolder
If fldContacts Is Nothing Then
strTitle = “Select Folder”
strPrompt = “Please select a Contacts folder”
MsgBox strPrompt, vbExclamation + vbOKOnly, strTitle
GoTo SelectContactFolder
End If
Debug.Print “Default item type: “ _
& fldContacts.DefaultItemType
If fldContacts.DefaultItemType <> olContactItem Then
MsgBox strPrompt, vbExclamation + vbOKOnly, _
strTitle
GoTo SelectContactFolder
End If
UpdateContacts:
Do While Not rstSource.EOF
Search for each contact in selected Contacts folder in case it already exists, and set a reference to it,
searching first by CustomerID and then by first name and last name (Outlook contacts may lack a
value in the CustomerID property):
strCustomerID = Nz(rstSource![CustomerID])
strSearch = “[CustomerID] = “ & Chr$(39) _
& strCustomerID & Chr$(39)
Debug.Print “Search string: “ & strSearch
blnDelete = rstSource![Delete]
Search by CustomerID.
Set con = fldContacts.Items.Find(strSearch)
If TypeName(con) = “Nothing” Then
Debug.Print “Customer ID “ & strCustomerID _
& “ not found in “ & fldContacts.Name & “ folder”
strFirstName = Nz(rstSource![FirstName])
strLastName = Nz(rstSource![LastName])
strSearch = “[FirstName] = “ & Chr$(39) _
Synchronizing Access and Outlook Contacts 11