Search With UserForm

  • I have written a code that acts as a directory search engine for peoples names. There is a form called search that is loaded and asks the user which name he or she would like to search for. When the user enters the data, whether the name is spelled right or not, the search finds the first closest match to whatever was entered into the form. I would like to change this in one way. Many times there are people with the same first name but different last name or two very similar first names that might be highlightes instead of the exact name the user is looking for. I would like to ask if anyone knows how to write a code that would insert each of the names that have all or part of the entered name into a forms box to where a final selection could be made to select the exact row of cells that the user wants to see. This is much like the find feature on your PC. You enter what you want to find and it brings up all of the things that include your keywords and you make the final selection. Is this possible or just very complicated?
    This is the current search code that I have written. It will find the closest match but will not insert it into a form but it is the best I can do to help with this project, because I am still learning the VBA language.

  • Re: specifying a search with a forms box.


    HI


    See if this will get you going.


    1) Run the macro aaa. This will bring up the first userform
    2) Enter the word apple or bananas
    3) Press the commandbutton
    4) This will bring up a second form with a combobox. Make a selection from the options.
    5) Press the button. This will show the selection you made, then close the form.


    HTH


    Tony

  • Re: specifying a search with a forms box.


    That is excellent. That is exactly what I wanted but is there a way to have the list drop right when you hit the sumbmit button instead of having a blank box being displayed.

  • Re: specifying a search with a forms box.


    howsabout;


    1) Run the macro aaa. This will bring up the first userform
    2) Enter the word apple or bananas into textbox1
    3) Press the commandbutton
    4) IF the search yeilded more than one result...
    4a) gather results and add results to combobox
    4b) textbox1.hide, combobox1.show
    4c) select choice from combobox
    5) Press the button. This will show the selection you made, then close the form.

  • Re: specifying a search with a forms box.


    Sorry for the like 6 month delay but I have been very busy with school. How could you write a code to do what you are saying. That is exactly what I want to do but I am having trouble with adding the items to a combobox and displaying it.

  • Re: specifying a search with a forms box.


    To Add an item to a combo box, use something like:


    Code
    Found_List.AddItem (This_Worksheet.Name)


    As an aside, you might also want to include a Soundex search in your code. This will return names that sound like the name typed in by the user.


    Regards


    Rich

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!