Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Searching Outlook Contacts from VBA fails

Posted on 2009-04-05
2
Medium Priority
?
248 Views
Last Modified: 2012-05-06
Attached is some code I am running to check for duplicate contacts in Outlook 2003 before inserting a new one from Access 2003. The adding part works fine so I have not included it here.
The problem is that the find method (Line 20) fails with the error:

The property "FirstName" in the condition is not valid.

Any example code I can find (even with this same property used in the search) seems to do the finding in exactly the same way as this, but mine won't work!
Any thoughts on what is wrong here?
Dim rst As New ADODB.Recordset
    Dim cnn As New ADODB.Connection
    Dim appOutlook As New Outlook.Application
    Dim ns As Outlook.Namespace
    Dim fldContacts As Outlook.MAPIFolder
    Dim itms As Outlook.Items, itm As Outlook.ContactItem
    Dim objContactFolder As Object
    Dim findstr As String
    
    Set cnn = CurrentProject.Connection
    Set appOutlook = CreateObject("Outlook.Application")
    Set ns = appOutlook.GetNamespace("MAPI")
    Set fldContacts = ns.GetDefaultFolder(olFolderContacts)
    Set itms = fldContacts.Items
 
    rst.Open "SELECT Employees.* FROM Employees WHERE Employees.EmployeeID=" & EmpID, cnn, adOpenKeyset, adLockOptimistic
    rst.MoveFirst
    
    'Prevent duplicate contacts in Outlook.
    findstr = "[FirstName] = """ & rst!FirstName & """ and [LastName] = """ & rst!LastName & """"
    Set itm = itms.Find(findstr)
    If Not TypeName(itm) = "Nothing" Then
      Rem dupicate
      If MsgBox("Do you want to update the information for " & rst!FirstName & " " & rst!LastName & "?", vbApplicationModal + vbYesNo + vbQuestion + vbDefaultButton1) = vbNo Then
          itm = Nothing
      End If
    End If

Open in new window

0
Comment
Question by:allaboutmike
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24074594
Nothing obviously wrong ... are you sure firstname and lastname are valid fields in your database record?

Chris
0
 

Accepted Solution

by:
allaboutmike earned 0 total points
ID: 24074644
Chris, thanks for the answer, but it seems that Outlook had some issue. I have gone back to get an exact dump of the error for you and now it works with no code changes!
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question