Can't get filter to filter by 'contains' (2 Viewers)

gojets1721

Registered User.
Local time
Yesterday, 17:54
Joined
Jun 11, 2019
Messages
189
So I've got a form that I'm using to allow the user to input info into some fields and then filter down a form.

One field is an employee name field and I can't seem to code it in a way that filters by 'contains' rather than 'equals. (I.e. if a user types in 'john', I would want fields with 'john smith' to populate in the report. But right now, you have to type 'john smith' in full to get the applicable entries to populate on the form)

Here is the code:

Code:
    If Not IsNull(frm!txtEmployeeName) Then
        If strWhere <> "" Then
         strWhere = strWhere & " AND "
        End If
        strWhere = strWhere & "[EmployeeName] LIKE '" & frm!txtEmployeeName & "'"
    End If

Any suggestions?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 01:54
Joined
Feb 19, 2013
Messages
14,696
you need to include asterix

strWhere = strWhere & "[EmployeeName] LIKE '*" & frm!txtEmployeeName & "*'"
 

June7

AWF VIP
Local time
Yesterday, 16:54
Joined
Mar 9, 2014
Messages
4,451
You should research use of wildcard characters with LIKE operator.
 

strive4peace

AWF VIP
Local time
Yesterday, 19:54
Joined
Apr 3, 2020
Messages
921
hi @templeowls

this phrase doesn't have any wildcards, which is why it behaves like =
LIKE '" & frm!txtEmployeeName & "'"

correct to be:
Code:
LIKE '*" & frm!txtEmployeeName & "*'"

so it begins and ends with a wilcard ~

oh, and I see that is exactly what @CJ_London suggested too!
 

Users who are viewing this thread

Top Bottom