Results 1 to 11 of 11
  1. #1
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188

    Search box criteria help

    Hi,


    I have three search boxes on my form using the code [CODE]Me.Filter = "
    Code:
     like '*" & FIND & "*'" & " AND [Location] like '*" & FIND2 & "*'" & " AND [Status] like '*" & FIND3 & "*'"
    Works perfectly, but all the locations start with a country code (e.g. IN Mumbai) If a user searches for "IN" locations it returns anything with the string "in" in it (e.g. US Kinston). How can I write the script to only search/return capital letters?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    Remove the leading * for locations?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    Quote Originally Posted by Welshgasman View Post
    Remove the leading * for locations?
    That doesn't work. Is there a way to only search the first two characters in a string? That may work

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    Quote Originally Posted by matey56 View Post
    That doesn't work. Is there a way to only search the first two characters in a string? That may work
    It will work?
    If you enter IN for location, then anything that starts with IN will get selected AS LONG as the other criteria does not exclude that data.

    Perhaps you should be using OR ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    Quote Originally Posted by Welshgasman View Post
    It will work?
    If you enter IN for location, then anything that starts with IN will get selected AS LONG as the other criteria does not exclude that data.

    Perhaps you should be using OR ?
    Help me out here. I'm not following. Where do I make these changes?

    Me.Filter = "[Code] like '*" & FIND & "*'" & " AND [Location] like '*" & FIND2 & "*'" & " AND [Status] like '*" & FIND3 & "*'"

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    How can I write the script to only search/return capital letters?
    StringComp() ?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    Me.Filter = "[Code] like '*" & FIND & "*'" & " AND [Location] like '*" & FIND2 & "*'" & " AND [Status] like '*" & FIND3 & "*'"
    Start learning to debug your code. Test just the location control until you get it correct. In fact test each individually.

    Code:
    Me.Filter = "Code like '*" & Me.FIND & "*'  AND Location like '" & Me.FIND2 & "*' AND Status like '*" & Me.FIND3 & "*'"
    Debug.Print Me.Filter

    Also get used to debugging the strings you build with Debug.Print to see if you have what you *think* you have.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188

    Talking

    Quote Originally Posted by Welshgasman View Post
    Start learning to debug your code. Test just the location control until you get it correct. In fact test each individually.

    Code:
    Me.Filter = "Code like '*" & Me.FIND & "*'  AND Location like '" & Me.FIND2 & "*' AND Status like '*" & Me.FIND3 & "*'"
    Debug.Print Me.Filter

    Also get used to debugging the strings you build with Debug.Print to see if you have what you *think* you have.
    That's why I'm here, because I don't know how to do that! I'm piecing this all together as I go with zero training.

  9. #9
    Join Date
    Jun 2022
    Posts
    28
    Code:
    INSTR(table.column, "IN", 0) > 0

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    Quote Originally Posted by matey56 View Post
    That's why I'm here, because I don't know how to do that! I'm piecing this all together as I go with zero training.
    Well see my links, that is what they are there for.
    Did you try my amendments?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    matey56 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2020
    Posts
    188
    Quote Originally Posted by Welshgasman View Post
    Well see my links, that is what they are there for.
    Did you try my amendments?
    Yes, I removed the asterisk correctly this time and I think it's working the way the user needs it to. I have mud on my face.

    Thank you VERY much!

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

Similar Threads

  1. Replies: 2
    Last Post: 03-27-2024, 10:05 AM
  2. Replies: 3
    Last Post: 09-12-2016, 11:49 AM
  3. Replies: 1
    Last Post: 03-26-2015, 11:08 AM
  4. Search Form - Dialog box asks for search criteria
    By faythe1215 in forum Queries
    Replies: 3
    Last Post: 02-10-2015, 05:54 PM
  5. Replies: 3
    Last Post: 01-04-2015, 06:09 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