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

    Listbox selection (Access XP)

    Is it possible to to know which item has been selected by a mouse click?

    On the other hand is it possible to know which item has been deselected by a mouse click?

    The reason I need to know this is to validate the item chosen

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listbox selection (Access XP)

    Can't you use the on click event and use the list index property ?
    Francois

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

    Re: Listbox selection (Access XP)

    Thanks Francois.

    What exactly do you mean by the List Index property?

    Would you give me an example please.

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

    Re: Listbox selection (Access XP)

    The ListIndex property is the zero-based index of the item clicked by the user (if no item is selected, ListIndex is -1).

    Example: say you have a list box named lstEmployees.

    Private Sub lstEmployees_Click()
    MsgBox "You clicked item # " & Me.lstEmployees.ListIndex
    End Sub

    If your list box is a simple multi-select list box, the On Click event will occur both when you select an item and when you deselect an item. The ListIndex property indicates the item clicked; you can use the Selected property to determine whether the item was selected or deselected:

    Private Sub lstEmployees_Click()
    If Me.lstEmployees.Selected(Me.lstEmployees.ListIndex ) Then
    MsgBox "You selected item # " & lstEmployees.ListIndex
    Else
    MsgBox "You deselected item # " & lstEmployees.ListIndex
    End If
    End Sub

    If you have a list box whose multiselect property is set to Extended, it is more complicated because you can (de)select multiple items at once using click+drag, Shift+click and Ctrl+click.

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

    Re: Listbox selection (Access XP)

    Thanks Hans and Francois. I have had my listboxes set to Extended but I will now set it to single. I don't need those complications with extended.

Posting Permissions

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