Items.find criteria

Status
Not open for further replies.
R

R2l0Y2hlIEd1bWVl

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?
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
When Find has returned an item, check its property.

Best regards

Michael Bauer

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?
 
R

R2l0Y2hlIEd1bWVl

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 " wrote:



> When Find has returned an item, check its property.

> > Best regards
> Michael Bauer

> > >

> 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?

>
 
R

R2l0Y2hlIEd1bWVl

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 " wrote:



> When Find has returned an item, check its property.

> > Best regards
> Michael Bauer

> > >

> 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?

>
 
Status
Not open for further replies.
Top