Share via

filter with like

Anonymous
2013-10-01T05:21:10+00:00

Hi,

I want to use 'Filter' to search by 'First Name' in my tblEmployees.

Me.Filter = " strFirstName= Like ' " &txtFilterFirstName& " * ' "

I want to add 'Like ' to use wildcard.

Do you think this is right code?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2013-10-01T07:37:25+00:00

I want to use 'Filter' to search by 'First Name' in my tblEmployees.

 

Me.Filter = " strFirstName= Like ' " &txtFilterFirstName& " * ' "

 

I want to add 'Like ' to use wildcard.

 

Do you think this is right code?

It seems to me that it's almost right, except that the equals operator (=) and the Like operator are mutally exclusive, and you seem to have extra spaces in the filter string.  In some places an extra space doesn't matter, but in other places it does.  I would write this:

    Me.Filter = "strFirstName Like '" & txtFilterFirstName & "*'"

That assumes that "strFirstName" is actually the name of the First Name field in your table.  Note also that this code will fail if txtFilterFirstName contains a single-quote or apostrophe (').  Maybe it would be better to use double-quotes around the specified name fragment, but to do that, you have to double up the double-quotes, like this:

    Me.Filter = "strFirstName Like """ & txtFilterFirstName & "*"""

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2013-10-01T22:52:35+00:00

    Thanks!!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-10-01T14:18:59+00:00

    Thank you so much!!

    I spent quiet some time to fix this but I couldn't.

    How can I learn these quotation marks? 

    You're welcome.

    At least in Access 2003, 2007, and 2010, there's an article in the online help file entitled "Quotation Marks in Strings".  The same article is posted online here:

        http://msdn.microsoft.com/en-us/library/office/aa212167(v=office.11).aspx

    That's the Access 2003 version, but I don't think it's any different among the various version of Access.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-10-01T10:57:06+00:00

    Thank you so much!!

    I spent quiet some time to fix this but I couldn't.

    How can I learn these quotation marks?

    Was this answer helpful?

    0 comments No comments
  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more