How to synchronize two contact folders using VBA?

  • Thread starter Paul George via OfficeKB.com
  • Start date
P

Paul George via OfficeKB.com

Hello,
Can someone help me with sample code to synchronize contact items in two folders?
If the contact already exists in the second folder, I want to just update all the fields. I can do this by assigning each field. But is there an easier way to do this? Here is what I have:
' thisItem is from the source contact folder.
' is there a better way to check if the item already exists in the target folder?
Set oldItem = targetFolder.Items.Find("[FullName] = '" + thisItem.FullName + "'")
If TypeName(oldItem) = "Nothing" Then
Set copyItem = thisItem.Copy
copyItem.Move targetFolder
Else
' is there a better way to synchronize the two items?
oldItem.MobileTelephoneNumber = thisItem.MobileTelephoneNumber
oldItem.HomeTelephoneNumber = thisItem.HomeTelephoneNumber
' ... Rest of the fields
oldItem.Save
End If

Thanks much,
Paul
 
E

Eric Legault [MVP - Outlook]

Your searching is fine.

As for updating all the fields, try looping through all the fields instead.
Ensure that you have appropriate error handling, as not all ItemProperties
are writable.

Sub CopyContact()
On Error Resume Next

Dim objCNew As Outlook.ContactItem, objCOld As Outlook.ContactItem, intX
As Integer
Dim objProp As Outlook.ItemProperty

'Add code to set valid references to objCOld and objCNew first

For intX = 1 To objCOld.ItemProperties.Count
Set objProp = objCOld.ItemProperties.Item(intX)
objCNew.ItemProperties(objProp.Name).Value = objProp.Value
Next
objCNew.Save

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