Results 1 to 5 of 5

Thread: File path code update needed
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,355
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default File path code update needed

    Hello I need help:


    Code:
    Dim sfile$, fpath$
    With Application
        Fpath = ThisWorkbook.Path  & .pathSeparator & “Pictures” & .pathSeparator 
        sFile = Dir(fPath & .PathSeparator & TextBox1.Text & “.*”)
    Image1.Picture  = LoadPicture(“”)
    If sFile<>”” Then Image1.Picture = LoadPicture(fPath & .pathSeparator & sFile)
    End With

    I am looking for a way to make sure that when I have say


    “Kelly mort” in the textbox and “mort kelly” in the image folder , I want it pick that file and show it in the control.


    For example if I have name “A B C” Then “B C A”, “A C B”, “C A B”, etc are all valid.


    I just got stacked.
    There Is Always A Better Way

  2. #2
    New Member
    Join Date
    May 2019
    Location
    Indiana, USA
    Posts
    46
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: File path code update needed

    Hi Kelly,
    You might be able to accomplish this by splitting your search string into separate strings and using instr() to find matches. This would require checking every file in the directory for matches to each search term. Something like this maybe:

    str_search1 = "Kelly"
    str_search2 = "Mort"

    'Grab your next file name here
    str_fileName = "Mort Kelly.xxx"

    if instr(1, str_fileName, str_search1, vbTextCompare) > 0 then
    if instr(1, str_fileName, str_search2, vbTextCompare) > 0 then
    'Found a file name that has both terms
    End If
    End If

  3. #3
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,355
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: File path code update needed

    Okay cool.

    But the is that there may be variable number of names .

    And I don't also understand this approach that much.

    Can you make it a bit clearer for me?
    There Is Always A Better Way

  4. #4
    New Member
    Join Date
    May 2019
    Location
    Indiana, USA
    Posts
    46
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: File path code update needed

    This was just a simple mockup not a full solution. The idea here is that you can get the name you are looking for in a string and split it into multiple search terms. Then you can search each of those terms individually. The instr() function searches for a search term anywhere in the string. If the first term is found, then we search for the second term. If they both are found, then you have a match.

  5. #5
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,355
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: File path code update needed

    Quote Originally Posted by BlueAure View Post
    This was just a simple mockup not a full solution. The idea here is that you can get the name you are looking for in a string and split it into multiple search terms. Then you can search each of those terms individually. The instr() function searches for a search term anywhere in the string. If the first term is found, then we search for the second term. If they both are found, then you have a match.

    Okay cool.

    Then let's do this.

    I am ready for any solution that works.
    There Is Always A Better Way

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •