Single quotes in filter string, how to manage????

  • Thread starter Wendi Taranto via OfficeKB.com
  • Start date
W

Wendi Taranto via OfficeKB.com

I want to filter Contact Items. If any of the values in the filter string
contain a single quote, there is parse error. How do you manage this type
of data and perform a successful filter?

My code follows:

strLast = "0'Brien"
strFirst = "Jeff"
strAddress = "401 Heavens Lane"
strCity = "Detroit"
strState = "MI"
strZip = "87633"

Dim objContactFolder As Outlook.MAPIFolder
Dim objFilteredItems As Outlook.Items
Dim objContactItems As Outlook.Items
Dim i As Integer
Dim objContactItem As Outlook.ContactItem

Set objContactFolder = objMAPI.GetDefaultFolder(10)
Set objContactItems = objContactFolder.Items
objContactItems.Sort "[LastModificationTime]", True

Set objFilteredItems = objContactItems.Restrict("[LastName] = '" &
strLast & "' And [FirstName] = '" & strFirst & "' And
[BusinessAddressStreet] = '" & strAddress & "' And [BusinessAddressCity] =
'" & strCity & "' And [BusinessAddressState] = '" & strState & "' And
[BusinessAddressPostalCode] = '" & strZip & "'")
 
M

Michael Bauer

Hi Wendi,

you need to use this notation please:

("[Lastname]=" & Chr(34) & sLast & Chr(34))
 
W

Wendi Taranto via OfficeKB.com

I tried this:

"[LastName] = " & chr(34) & O'Brien" & chr(34) & " And [FirstName] = "Jack"
And [BusinessAddressStreet] = "" And [BusinessAddressCity] = "" And
[BusinessAddressState] = "" And [BusinessAddressPostalCode] = """


And this:

"[LastName] = " & chr(34) & "O'Brien" & chr(34) & " And [FirstName] =
'Jack' And [BusinessAddressStreet] = '' And [BusinessAddressCity] = '' And
[BusinessAddressState] = '' And [BusinessAddressPostalCode] = ''"

Both return zero results. If I just filter by this:

Set objFilteredItems = objContactItems.Restrict("[LastName] = " & Chr(34) &
strLast & Chr(34))

I get the record that I expect to see. But the problem is, I want to
filter on additional conditions. How is this accomplished?????
 
M

Michael Bauer

Hi Wendi,

probably the fields, like BusinessAddressStreet, don´t exist. OL creates
them not before they´re needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top