Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Jan 2001
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Listboxes - deselecting an item (Acc 97 SR-2)

    Does anyone know how to clear the selection in a Listbox?

    I am using a series of Listboxes from which a user can select criteria in order to filter the output of a report. Some of them are multi-select, others are not.

    I want to be able to clear all the selections in all the listboxes after the report has printed so the user has to make completely new selections for a subsequent report.

    The control only has 2 properties, neither of which I can leverage to achieve my result.

    I can't believe I have to post this question. But I can't afford to waste any more time on it.

    Looking forward to hearing how easy it is!

    Thanks,
    Rich P.
    (humbled by a 2-property control!)

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Listboxes - deselecting an item (Acc 97 SR-2)

    Have you tried requerying the listbox? How you deselect depends on the kind of listbox it is. Is it simple or multiselect?
    Charlotte

  3. #3
    Lounger
    Join Date
    Jan 2001
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listboxes - deselecting an item (Acc 97 SR-2)

    First of all, thanks so much for the timely response. It is exaclty what I needed. Though I know I would not have found this anywhere else!
    For anyone interested, I used Hans' solution with a slight modification. I have a few listboxes to clear, so I created a function that takes a Listbox control as an argument. Also, in order to clear the selection where the first item in the list is selected, I changed the counter in the loop to begin at '0' instead of '1'.

    Private Function ResetList(lst As Access.ListBox)
    Dim i As Integer

    For i = 0 To lst.ListCount - 1
    lst.Selected(i) = False
    Next i

    End Function

    Then I can call this function from a command button placed next to a listbox control on the form:

    Private Sub cmdResetPgmMgr_Click()
    Call ResetList(Me.lstStaff)
    End Sub

    Thanks again for the answer. I should have asked sooner, rather than waste all that time.

    Regards,

    Rich P.

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

    Re: Listboxes - deselecting an item (Acc 97 SR-2)

    <P ID="edit" class=small>(Edited by HansV on 28-Feb-03 17:18. corrected error in loop index)</P>Are you using a custom control? The standard list box that comes with Access has many more than 2 properties.

    To deselect all items in a standard Access list box, you can use

    Dim i As Integer
    For i = 0 To lbxSomething.ListCount - 1
    lbxSomething.Selected(i) = False
    Next i

    where lbxSomething is the name of the list box.

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

    Re: Listboxes - deselecting an item (Acc 97 SR-2)

    Rich,

    You are correct in letting the loop index vary from 0 to ListCount - 1. The list index is zero-based. I have modified my previous reply.

Posting Permissions

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