Results 1 to 7 of 7
  1. #1
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41

    How to filter by contain

    This code only works for exactly equal in filter.



    Code:
        Forms("frmMain").Filter ="[Remarks] = " & Chr(34) & Me.Remarks & Chr(34)
        Forms("frmMain").FilterOn =True
    I also try to replace the = to Like still not working.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    try

    Forms("frmMain").Filter ="[Remarks] Like '*" & Me.Remarks & "*'"

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    If you want to do wildcard pattern matching:

    Forms("frmMain").Filter = "[Remarks] LIKE '*" & Me.Remarks & "*'"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    To match everything before and after the string in Me.Remarks, try
    Code:
        Forms("frmMain").Filter = "[Remarks] Like " & Chr(34) & "*" & Me.Remarks & "*" & Chr(34)
        Forms("frmMain").FilterOn = True
    To match anything before the string in Me.Remarks, try
    Code:
        Forms("frmMain").Filter = "[Remarks] Like " & Chr(34) & "*" & Me.Remarks & Chr(34)
        Forms("frmMain").FilterOn = True
    To match anything after the string in Me.Remarks, try
    Code:
        Forms("frmMain").Filter = "[Remarks] Like " & Chr(34) & Me.Remarks & "*" & Chr(34)
        Forms("frmMain").FilterOn = True

  5. #5
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Nothing is happening when i clicked the search button, no error either.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Where did you have the code? Post the event code.

  7. #7
    margzj is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Dubai
    Posts
    41
    Thank you this is working

    Quote Originally Posted by ssanfu View Post
    To match everything before and after the string in Me.Remarks, try
    Code:
        Forms("frmMain").Filter = "[Remarks] Like " & Chr(34) & "*" & Me.Remarks & "*" & Chr(34)
        Forms("frmMain").FilterOn = True
    To match anything before the string in Me.Remarks, try
    Code:
        Forms("frmMain").Filter = "[Remarks] Like " & Chr(34) & "*" & Me.Remarks & Chr(34)
        Forms("frmMain").FilterOn = True
    To match anything after the string in Me.Remarks, try
    Code:
        Forms("frmMain").Filter = "[Remarks] Like " & Chr(34) & Me.Remarks & "*" & Chr(34)
        Forms("frmMain").FilterOn = True

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 06-26-2017, 12:41 PM
  2. Replies: 2
    Last Post: 02-20-2017, 11:28 PM
  3. Replies: 0
    Last Post: 03-18-2016, 09:13 PM
  4. Replies: 9
    Last Post: 02-24-2015, 11:19 AM
  5. Replies: 28
    Last Post: 03-08-2012, 06:47 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums