Link to home
Start Free TrialLog in
Avatar of SchoolTeacher54

asked on BindingSource Filter string

I have a windows form that uses filters on the on [bindingsource]
I am trying to get a search criteria that is found anywhere in a string to return in the filter results.
[exisiting code] Master_ContactsBindingSource.Filter = "c_company = '" & InStr(CompanySearch.Text, 1) & "'"

The problem is that I receive no results (and does not error either) for terms that I know are in the table such as "son".

The desired result is to return all records that contain the search term "son" but clearly I have this wrong.

c_company = [table field]
[CompanySearch.text] is the textbox with the search term

Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

as per the documentation (, your arguments seems to be in an incorrect order. I think it should be:
Master_ContactsBindingSource.Filter = "c_company = '" & InStr(1, CompanySearch.Text) & "'"

Open in new window

Avatar of SchoolTeacher54



I 'think' I had that sequence somewhere along the way of experimenting. I corrected the string to read as you indicated (I agree with it) however I still receive no results for something such as 'b'. To sort this out I've included some strings that DO work in other areas of the program for reference. I know the field and string captures correctly. The hangup is when I get to the Instr (issue).

Master_ContactsBindingSource.Filter = "c_company like '" & CompanySearch.Text & "*'"
Master_ContactsBindingSource.Filter = "c_address <>''  And  c_company Like '" & CompanySearch.Text & "*'"

I appreciate your help!


Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

I found that the following works perfect. Boy was I climbing the wrong side of the tree!

Master_ContactsBindingSource.Filter = "c_company like '%" & CompanySearch.Text & "%'"

I get any occurrence of a string which was the goal.

Thank you for the poke Eric!