By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,560 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,560 IT Pros & Developers. It's quick & easy.

Filter report using like operator

P: 1
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
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,418

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.