Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search by Columns in ListBox (2003)

    Thanks to HansV I've been able to achieve things that would have taken me years to master. I have one more request, and pray that I can get the usual help.

    I have a form (frmSubjectInformationScreen) that has a ListBox called "lstSearch". It is populated from two fields in the table "Agents_Agencies". The fields are "Agent_AgencyName" and "SubjectID". "Agent_AgencyName" is a text field and "SubjectID" is a number field.

    Ideally, I would like to be able to search the ListBox by either column. The "SubjectID" search would require the user to enter the exact number. However, I would like to search the "Agent_AgencyName" column with only a few characters, like the beginning of a string. The "Agent_AgencyName" column in the ListBox is already ordered in alpha order, ascending.

    As usual,any guidance is appreciated. Thanks in advance!

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Search by Columns in ListBox (2003)

    First of all what do you want to do with this list box, is it bound to a field in the table that is the source of the form?

    I think you probably mean a combo box rather than a list box where you can select a number or a name. You cannot enter a value when searching in a list box but you can with a combo box.

    I have built an example database for you to look at.

    It basically allows you to select via a option box which to select in the combo box. Check the code behind the form.
    Attached Files Attached Files

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search by Columns in ListBox (2003)

    Thanks for the help, patt!

    Your file opened some possibilities for me. Unfortunately, it doesn't do what I'm looking for. I just want to enter a number or string in a TextBox, have the user click on a command button, and have the program look in a ListBox for the value entered. If it's found, I want the ListBox to display the row where it was found; if not found, I want a MsgBox to come up. Hope you can assist. Thanks!

    PS: My ListBox is unbound.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Search by Columns in ListBox (2003)

    What you could do is to populate a list box with the results of what you entered in the textbox using a Like selector for the text chars you input.

    The list box would be a list rather than a table or query.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search by Columns in ListBox (2003)

    Thanks to everyone for your help! Learned a whole lot with your suggestions. Found the solution to my problem elsewhere. Would like to share it but I don't know if it's acceptable to post code so obtained. Also, I don't want to create the impression that I came up with the code myself (like someone here would believe it, right!). If I get your go ahead, will gladly post the solution. The best to all of you. Thanks!

  6. #6
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Search by Columns in ListBox (2003)

    There should be no reason not to show the code/

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search by Columns in ListBox (2003)

    If you got the solution from another forum or newsgroup, you can post a link to the relevant thread, or you can post the solution here with an acknowledgement of its source.

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search by Columns in ListBox (2003)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    I found the solution here: http://www.tek-tips.com/viewthread.cfm?qid=1005919. Like here, registration is required. Used some of HansV and patt ideas to tweak it a little bit like, in addition to entering the suggested code in the query, I set the query to sort ascending on the field containing agent's names. Hope this helps!

Posting Permissions

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