select and unselect a list box item

How can I select or unselect individual items in a multiselect list box?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hold your CTL key down while you click your mouse
calvinrsmithAuthor Commented:
sorry, I meant in code.
Here's my code to set a particular program name to selected. Hope it makes sense (see the VALUE property). Basically I search through my items if my list box - if I find the item that matches the value I'm looking for - I select it using the Value property.

Dim frm As Form
    Dim i As Integer
    Dim myCompare As Variant
    Set frm = Forms("frm_SCRPRMasterList")
    myCompare = frm![cmb_Programs]
        Set ctl = Me![cmb_Programs]
        varitem = ctl.ListCount
        For i = 0 To varitem - 1
            If myCompare = Val(ctl.Column(2, i)) Then
                ctl.Value = i
                Exit For
            End If
        Next i

You can also use the Select property

mylistbox.selected(indexnumber) = true

This will work in most cases - but in my example above - the Value property forced the list box to be POSITIONED at the selected field so if the value was way down the list - the user would see right away that it was selected.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
calvinrsmithAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.