• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Find outlook contact and update, or add new

Access and Outlook 2003 using Outlook 11.0 Object Library reference

I've spent quite a long time searching for a way to add contacts to outlook programmatically from an access form.  I was successful in adding new contacts with data from the current record on the form.  The problem is, if the contact already exists, it will create a duplicate contact.  What I can't figure out is how to check if the contact exists.  

This is basically what I want to do (the code is not all there but I hope you get the idea):

If the contact exists then

  Dim Update_Contact As Integer
  Update_Contact = MsgBox("Contact Found." & vbCrLf & "Do you want to update the contact information?", vbYesNoCancel)
  Select Case Update_Contact
    Case vbYes
        'open the contact
        'update with contact info from the current record
        'save the contact
        exit sub
    Case vbNo
        'open the contact to view
        exit sub
    Case vbCancel
        exit sub
  End Select

Else

  'add new contact with info from the current record
  'save the contact

End If


I Just need to know how to check if the contact exists, I have the rest of it worked out already.

Thanks,

Traigo
0
traigo
Asked:
traigo
  • 2
1 Solution
 
jimcrintCommented:
I use this bit of code to see if they exist and then if they dont I then add a new one  

  For Each obj In objItems
        If obj.Class = olContact Then
            Set objContact = obj
                If objContact.FirstName = rst.Fields("FirstName") And objContact.LastName = rst.Fields("Surname") Then
                    With objContact
                        rst.Edit
                        .CompanyName = rst.Fields("Company")
                        .FirstName = rst.Fields("FirstName")
                        .LastName = rst.Fields("Surname")
                        .BusinessAddress = rst.Fields("Address") & Chr(13) & rst.Fields("Suburb") & Chr(13) & rst.Fields("City")
                        .Body = rst.Fields("Description")
                        .BusinessFaxNumber = rst.Fields("Fax")
                        .Email1Address = rst.Fields("Email")
                        .MobileTelephoneNumber = rst.Fields("Mobile")
                        .BusinessTelephoneNumber = rst.Fields("Phone")
                        .Save
                        count = count + 1
                        rst.Fields("update") = False  ' this is used fro tracking what has been changed in the database
                        rst.Update
 
                    End With
                End If
        End If
    Next obj
0
 
traigoAuthor Commented:
thanks for the quick response jimcrint.  I will try it first thing in the morning and post back
0
 
traigoAuthor Commented:
GREAT! THANKS!  I was able to get it working.

If you are familiar with the calendar object too, keep an eye out, I may be posting with questions on that soon too.

Thanks again,

Traigo
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now