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
'Prevent duplicate contacts in Outlook.
findstr = "[FirstName] = """ & rst!FirstName & """ and [LastName] = """ & rst!LastName & """"
Set itm = itms.Find(findstr)
If Not TypeName(itm) = "Nothing" Then
If MsgBox("Do you want to update the information for " & rst!FirstName & " " & rst!LastName & "?", vbApplicationModal + vbYesNo + vbQuestion + vbDefaultButton1) = vbNo Then
itm = Nothing