Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Outlook Contacts from MS Access

Status
Not open for further replies.
Mar 10, 2004
53
US
Access 2000 / Outlook 2000

I have an Access contact form in which I would like to add a command button that will save the current contact to Microsoft Outlook Contacts or update and existing contact.

I've read through the FAQ and posts and got the following code on how to do this. The problem that I have now is that its only adding and not doing an update. Every time I hit the command button it adds a new contact regardless it the contact already exists.

Can't seem to find any docs on doing just an update. Any help is greatly appreciated.

Thanks in advance.

P.S. Also, instead of hardcoding the mailbox name (eg. Mailbox - Doe, John) is there a generic name/value to replace this?

---------------------

Private Sub AddToOutlook_Click()

Dim OutlookObj As Outlook.Application
Dim Nms As Outlook.namespace
Dim myContacts As Object
Dim myItems As Object
Dim MyItem As Object
'Dim DB As Database
Dim Rst As Recordset

Set Rst = Me.Recordset
Set OutlookObj = CreateObject("Outlook.application")
Set Nms = OutlookObj.GetNameSpace("MAPI")

Set myContacts = Nms.Folders.Item("Mailbox - Doe, John").Folders.Item("Test Contacts")
Set myItems = myContacts.items

Set MyItem = myItems.add("IPM.Contact.MyContactForm")

With MyItem
.FullName = Me![Name].Value
.CompanyName = Me![Company].Value
.Close (olSave)
End With

End Sub
 
Figured it out. Here's the solution for anyone who's interested.


'Code to search items in contacts if it already exists.
Set myContact = myContacts.Items.find("[Fullname] = " & Me![Name].Value)


If Not TypeName(myContact) = "Nothing" Then
MsgBox Me![Name].Value & " is already in your Contact list in Outlook."
Exit Sub
Else
(Add code to add to outlook contacts here...)
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top