Unselect select all listbox

JonnyToppa

New member
Local time
Today, 15:56
Joined
Jan 25, 2012
Messages
5
Hello
Im using Access 2007 and have searched previous threads.
Ive got a listbox with a Select All option. List.Selected=True with loop is working for Select All but how can I unselect all?

Thanks
 
You could put a clear filter button on your form, then put this code in the on click event for the button.
Code:
me.listboxname = Null
me.requery
 
Hello Alan

Ive tried that and its ok but, it would be better if the Select All list item could be toggled as such rather than have a seperate button. A simple List.Select=False with loop will unselect all the list items but makes other individual items unselectable so, at this point Im stumped.

Thanks
 
Last edited:
This should do what you need just written it for the same situation so if you press select all with anything but all of them selected it selects them all

but if they're already selected it clears them

Code:
Public Function LstSelectAll(Lst As ListBox) As Boolean
Dim lngRow As Long
Dim isLstSelectAll As Boolean
    If Lst.MultiSelect Then
        For lngRow = 0 To Lst.ListCount - 1
            If Lst.Selected(lngRow) = True Then
                isLstSelectAll = True
            Else
                isLstSelectAll = False
                Exit For
            End If
        Next
    End If
    
    If isLstSelectAll = False Then
        If Lst.MultiSelect Then
            For lngRow = 0 To Lst.ListCount - 1
            Lst.Selected(lngRow) = True
            Next
            LstSelectAll = True
        End If
    Else
        If Lst.MultiSelect Then
            For lngRow = 0 To Lst.ListCount - 1
            Lst.Selected(lngRow) = False
            Next
            LstSelectAll = False
        End If
    End If
    
End Function
 

Users who are viewing this thread

Back
Top Bottom