467,917 Members | 1,406 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,917 developers. It's quick & easy.

Filter report using like operator

I have the code for filtering report on multiple selections in a list box, but how do I modify the following code to use "like" operator instead of "in". I tried to replace:
strWhere = "[MyField] LIKE ('*" & Left$(strWhere, lngLen) & "*')"
strWhere = "[MyField] IN (" & Left$(strWhere, lngLen) & ")"
but it doesn't work. Anyone could help?

Dim vItem As Variant
Dim lngLen as Long

With Me.MyListbox
For Each vItem In .ItemsSelected
If Not IsNull(vItem) Then
strWhere = strWhere & """" & .ItemData(vItem) & """, "
End If
End With
lngLen = Len(strWhere) - 2 'Without trailing comma and space.
If lngLen > 0 Then
strWhere = "[MyField] IN (" & Left$(strWhere, lngLen) & ")"
End If
Oct 4 '06 #1
  • viewed: 3901
1 Reply
Expert 1GB

In is supposed to be used with series of values...
In (1, 2, 3, 5, 8)

With your string do you give a serie of values?

Or if it's an sql it should be:

In (SELECT MyNumber FRM Numbers)

So there is the syntax for subquery and not for an ordinary query!

Oct 8 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by CSDunn | last post: by
8 posts views Thread by dick | last post: by
1 post views Thread by lorirobn | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.