Get First Selected Item In A Listbox

Posted on 2006-05-17
Last Modified: 2008-02-26
I have a list box. The user can select multiple lines in the list box. How do I get the row and column of the first line they select in the list box? Say they select row 3, 7, 9, 11. I need the .column(row, column) for line 3.

Any help will be greatly appreciated!
Question by:hpp123
    LVL 65

    Expert Comment

    just use 0,0

    dim bLoop as Boolean
    dim i as integer
    dim sVal as string

    bLoop = True
    sval = ""
    do while bLoop = True

        if i > lstbox.ListCount-1 then
            bLoop = False
         elseif lstbox.selected(i) = True
            bloop = false
            sVal = lstbox.selected(i)
         end if

    if sVal <> "" then msgbox "First item = " & sVal

    LVL 65

    Accepted Solution

    slight mods

    forgot the then
    elseif lstbox.selected(i) = True then

    and to get the value
    sVal = lstbox.column(i,0)           'this gets value from column 0

    Author Comment

    That did the trick! Thank you!!!
    LVL 65

    Expert Comment

    no probs

    note sVal is set to nothing if no selections made


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    755 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

    22 Experts available now in Live!

    Get 1:1 Help Now