Programmatically select an item in a ListBox control

Posted on 2004-11-19
Last Modified: 2008-03-17
At runtime, how do I programmatically select an item in a ListBox control.

The result would be as if I had clicked on it with the mouse.....meaning the underlying event would fire.
Question by:knowlton
    1 Comment
    LVL 50

    Accepted Solution

    You would use the .Selected property of the listbox.  For example, to select the first item, use this line of code:

    Me.MyListboxName.Selected(0) = True

    Selecting an item programmatically will not fire the OnClick event for the listbox.  Only a mouse click will do that.  You CAN call the event manually, however.  For example, to select the fourth item in the listbox, then fire the event:

    Me.MyListboxName.Selected(3) = True

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now