Access VBA listbox value while still typing

Posted on 2012-08-19
Last Modified: 2012-08-20
I have a form with a bound listbox, with only one column - a string field of job numbers.

While the user types I want to check whether there is no match, and give a message along the lines of "There is no match for this job."

For a text box I would have to use txtField.text on a key press event, as txtField.value does not yet have what has been typed.

For the listbox, the keypress event is being triggered, but cboList.text is still empty after typing my first character.

What should I use to find the value of the listbox so far, on each key press?

Thank you.
Question by:MonkeyPie
    LVL 61

    Assisted Solution

    You can't do what you are asking with a listbox alone.  There is no text property for a listbox like there is for a textbox or combo.

    You can however do something similar - filtering a listbox with a textbox using code that filters the listbox as the user types in the textbox, character by character.

    The sample in this article has an example of this:

    When the database opens to the main form, click the button in the bottom right corner for the listbox search demo.  The demo usies a combo box to catch the keystrokes, but a textbox could be used in the same manner.
    LVL 48

    Accepted Solution

    I believe both of your requests are dealt with here:

    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    The Previous two Experts have got you covered..., so I don't want any points...

    Just a note.

    Anytime you want something to happen "as you type" can takes a lot of resources.

    If the list of values to search will remain relatively small, then no problem.

    But as ( ...or if) the list grows, you may notice that it takes longer and longer to work because it has to search more and more records.


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now