Avoiding duplicate Contact info

M

Martin

Hi,

I've written a VB program to dump all contact info from
our helpdesk system and added these 1631 contacts to
outlook - fine.

Run it a second time and it does not update the existing
outlook contact but creates another 1631 duplicate
records.

How can I change the following to do updates instead of
inserts for existing records?

Codes is as follows:

If Not m_ContactsRS.EOF Then

MsgBox "Currently processing data with Outlook, please
wait", vbOKOnly, "CrossCompass"
Screen.MousePointer = vbHourglass

' Start Outlook.
' If it is already running, you'll use the same
instance...
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

' Logon. Doesn't hurt if you are already running and
logged on...
Dim olNs As Outlook.Namespace
Set olNs = olApp.GetNamespace("MAPI")
olNs.Logon

' Create and Open a new contact.
Dim olItem As Outlook.ContactItem

' Setup Contact information...

While Not m_ContactsRS.EOF

Set olItem = olApp.CreateItem(olContactItem)

With olItem
.CompanyName = Format(m_ContactsRS.Fields
(0).Value)
.FullName = Format(m_ContactsRS.Fields(1).Value)
.CompanyMainTelephoneNumber = Format
(m_ContactsRS.Fields(2).Value)
.MobileTelephoneNumber = Format
(m_ContactsRS.Fields(3).Value)
.Email1Address = Format(m_ContactsRS.Fields
(4).Value)
End With

' Save Contact...
olItem.Save

m_ContactsRS.MoveNext
m_iRow = m_iRow + 1

Wend

m_ContactsRS.Close

olNs.Logoff

Set olNs = Nothing
Set olItem = Nothing
Set olApp = Nothing

Set m_ContactsRS = Nothing

Screen.MousePointer = vbNormal
MsgBox m_iRow & " Outlook Contacts Synched with
BridgeTrak", vbOKOnly, "CrossCompass"


Any comments appreciated
 
S

Sue Mosher [MVP-Outlook]

Use the MAPIFolder.Items.Find method to search for the matching CompanyName.
 
M

Martin

Sue,

I found out an example of using Find/Restrict and filters
for both the companyname and Fullname but surely there
must be a unique ID assigned to each contact therefore

searchable by that ID or if contact is foun then issue an
UPDATE instead of a SAVE

Any advice appreciated.

Thanks
Martin
 
S

Sue Mosher [MVP-Outlook]

Each Outlook item has an EntryID property that's unique, at least within the
store. You can use it with the Namespace.GetItemFromID method to retrieve an
individual item.
 
M

Martin

Sue,

There doesn't seem to be an update action only addition
i.e. Set olItem = olApp.CreateItem(olContactItem)

so me building up a list of contacts details in an array
and then comparing them against the SQL RS is pointless
if

the olItem.Save is preceded by olApp.CreateItem
(olContactItem) syntax

surely there must be an update equivalent to the
createitem ???

Thanks
Martin
 
S

Sue Mosher [MVP-Outlook]

What's this about? The newsgroup interface you are using apparently does not
quote earlier messages in the thread, making your latest message so short on
detail that we've lost track of your original question.. Please take the
time to quote the original message.

CreateItem creates a new item. If you want to update an item, you need to
get it as an object (various methods, depending on the application), change
its properties, then use the Save method.
 

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