Items.find criteria

  • Thread starter Thread starter Gitche Gumee
  • Start date Start date
G

Gitche Gumee

I am using the following code to select a contact for updating.

Set myItem = myContacts.Items.Find("[FirstName] = " & strFirstName & " and
[LastName] = " & strLastName & "")

This works, but I also need to check that another field [Customer ID] is
null before making the update. Is that possible?
 
This is helpful, but I'm still having trouble. I'm new to Outlook VBA; maybe
I don't know the right syntax.

Here's my code:

Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts)
Set myItem = myContacts.Items.Find("[FirstName] = " & strFirstName
& " and [LastName] = " & strLastName & "")

While TypeName(myItem) <> "Nothing"
If IsNull(myItem.CustomerID) Then
myItem.CustomerID = strCustomerID
myItem.User2 = strEntryID
myItem.Save
End If
Set myItem = myContacts.FindNext
Wend

The error number is 438, "Object doesn't support this property or method."

I have also tried <If myitem.CustomerID = "">, with same error.



Michael Bauer said:
When Find has returned an item, check its property.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Sat, 18 Apr 2009 17:12:01 -0700 schrieb Gitche Gumee:
I am using the following code to select a contact for updating.

Set myItem = myContacts.Items.Find("[FirstName] = " & strFirstName & " and
[LastName] = " & strLastName & "")

This works, but I also need to check that another field [Customer ID] is
null before making the update. Is that possible?
 
Got it. Here is the fixed code:

Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts).Items

Set myItem = myContacts.Find("[FirstName] = """ & strFirstName &
""" and [LastName] = """ & strLastName & """"

While TypeName(myItem) <> "Nothing"
If myItem.CustomerID = "" Then
myItem.CustomerID = strCustomerID
myItem.User2 = strEntryID
myItem.Save
End If

Set myItem = myContacts.FindNext

Wend






Michael Bauer said:
When Find has returned an item, check its property.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Sat, 18 Apr 2009 17:12:01 -0700 schrieb Gitche Gumee:
I am using the following code to select a contact for updating.

Set myItem = myContacts.Items.Find("[FirstName] = " & strFirstName & " and
[LastName] = " & strLastName & "")

This works, but I also need to check that another field [Customer ID] is
null before making the update. Is that possible?
 
Back
Top