Results 1 to 8 of 8
  1. #1
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328

    Filtering for Ends With

    Probably simple, but driving me nuts. I want to filter a list for entries that end with certain characters. If I put the characters in the code, like this:



    Form.Filter = "[Item] Like '" & "*" & "M28'"
    it works fine.

    How do I refer to a control instead having to write the characters in the code?. I have no problems with "begins with" or "Contains", but can't seem to find the right combo of quotation marks and apostrophes to make "ends with" work.

    An aside: Is there some site that explains the logic of using quotation marks, and apostrophes and parentheses in vba filter expressions?. I just copy them, but somehow miss the logic associated with them (as you can tell from my question.)

    Any help much appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You could try this (untested)

    Form.Filter = "[Item] Like '*M28'"

  3. #3
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    My question was how do I substitute "M28" with a me.controlName. If I type the desired end in quotation marks in the code expression, no problem. I want to be able to enter desired " ends with" in a control on a form, then have the code use that value as a filter.

    Quote Originally Posted by orange View Post
    You could try this (untested)


    Form.Filter = "[Item] Like '*M28'"

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    How about (still untested)

    Form.Filter = "[Item] Like " & "'*" & Me![Text0] & "'"

  5. #5
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Must be something wrong with my Access. I tried above and acted like Contains rather than Ends With. I will run a repair and try code as you show it. Thanks for following up. If you get a chance to test, would appreciate it much. I am going nuts.

  6. #6
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I tested this on another computer with A2003. It also acts like a "contains" expression rather than an "Ends With". Is this some problem with Access? Any other ideas?

    Quote Originally Posted by gg80 View Post
    Must be something wrong with my Access. I tried above and acted like Contains rather than Ends With. I will run a repair and try code as you show it. Thanks for following up. If you get a chance to test, would appreciate it much. I am going nuts.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The syntax for the LIKE and wildcard expression provided by orange is correct. Should return only those records where the value ends with M28.

    However, I am somewhat surprised by the success with Form prefix. Where is this code?

    Could eliminate one concatentation although the results should be same. And I use dot to reference controls.

    Form.Filter = "[Item] Like '*" & Me.Text0 & "'"
    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.

  8. #8
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Just to be sure, I created a new form sourced from another table and your last expression works fine. Must be some bug or corruption.

    Thanks so much- Really appreciate the help. Without this site I would give up.

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

Similar Threads

  1. Two Front-Ends - Best Practices?
    By rhubarb in forum Database Design
    Replies: 3
    Last Post: 06-23-2014, 11:57 AM
  2. Replies: 2
    Last Post: 09-11-2012, 12:34 PM
  3. Back Ends, Outgrow Access???
    By redbull in forum Programming
    Replies: 3
    Last Post: 07-26-2012, 09:48 AM
  4. Splitting and multiple front ends
    By thart21 in forum Access
    Replies: 2
    Last Post: 07-08-2011, 02:17 PM
  5. distributing Access front ends
    By gunner in forum Access
    Replies: 10
    Last Post: 03-15-2011, 03:53 PM

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