I have written code which search contact based on email id and needs to display Contact Form, every other part is working but .Display property is not showing Contact Form for searched Contact.
My code:
Dim strWhere As String
Dim colItems As Outlook.Items
Dim blnFound As Boolean
Dim strAddress As String = emailAddress
ContactName = ""
FTPSite = ""
strWhere = "[Email1Address] <> vbNullString " & _
"Or [Email2Address] <> vbNullString " & _
"Or [Email3Address] <> vbNullString "
strWhere = "[Email1Address] = '" & strAddress & "'" & _
"Or [Email2Address] = '" & strAddress & "'" & _
"Or [Email3Address] = '" & strAddress & "'"
colItems = oContactFolder.Items.Restrict(strWhere)
If String.IsNullOrEmpty(strAddress) = False Then
colItems.SetColumns("FirstName, FTPSite, Email1Address, Email2Address, Email3Address")
For Each objItem In colItems
' must test for item type to avoid distribution lists
If TypeName(objItem).ToString = "ContactItem" Then
Dim contactItem As Outlook.ContactItem = _outlookApplication.CreateItem(OlItemType.olContactItem)
contactItem = TryCast(objItem, Outlook.ContactItem)
If InStr(contactItem.Email1Address, strAddress) > 0 Or _
InStr(contactItem.Email2Address, strAddress) > 0 Or _
InStr(contactItem.Email3Address, strAddress) > 0 Then
ContactName = contactItem.FirstName
FTPSite = contactItem.FTPSite
'If Not String.IsNullOrEmpty(FTPSite) Then
__contactItem.Display()__
blnFound = True
Exit For
End If
End If
Next
End If
colItems = Nothing
Return blnFound
Kindly assist.
My code:
Dim strWhere As String
Dim colItems As Outlook.Items
Dim blnFound As Boolean
Dim strAddress As String = emailAddress
ContactName = ""
FTPSite = ""
strWhere = "[Email1Address] <> vbNullString " & _
"Or [Email2Address] <> vbNullString " & _
"Or [Email3Address] <> vbNullString "
strWhere = "[Email1Address] = '" & strAddress & "'" & _
"Or [Email2Address] = '" & strAddress & "'" & _
"Or [Email3Address] = '" & strAddress & "'"
colItems = oContactFolder.Items.Restrict(strWhere)
If String.IsNullOrEmpty(strAddress) = False Then
colItems.SetColumns("FirstName, FTPSite, Email1Address, Email2Address, Email3Address")
For Each objItem In colItems
' must test for item type to avoid distribution lists
If TypeName(objItem).ToString = "ContactItem" Then
Dim contactItem As Outlook.ContactItem = _outlookApplication.CreateItem(OlItemType.olContactItem)
contactItem = TryCast(objItem, Outlook.ContactItem)
If InStr(contactItem.Email1Address, strAddress) > 0 Or _
InStr(contactItem.Email2Address, strAddress) > 0 Or _
InStr(contactItem.Email3Address, strAddress) > 0 Then
ContactName = contactItem.FirstName
FTPSite = contactItem.FTPSite
'If Not String.IsNullOrEmpty(FTPSite) Then
__contactItem.Display()__
blnFound = True
Exit For
End If
End If
Next
End If
colItems = Nothing
Return blnFound
Kindly assist.