Can't get filter to filter by 'contains' (1 Viewer)

gojets1721

Registered User.
Local time
Today, 02:13
Joined
Jun 11, 2019
Messages
429
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, 10:13
Joined
Feb 19, 2013
Messages
16,607
you need to include asterix

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

June7

AWF VIP
Local time
Today, 01:13
Joined
Mar 9, 2014
Messages
5,466
You should research use of wildcard characters with LIKE operator.
 

strive4peace

AWF VIP
Local time
Today, 04:13
Joined
Apr 3, 2020
Messages
1,003
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