- database solutions and downloads for microsoft access

Microsoft Access Listbox

How to Clear a Multi-Select Listbox

If you are using a Microsoft Access listbox on your form, you can set properties to allow the database user options as to how they make selections within the list box.

The MultiSelect property uses the following settings:

Setting Visual Basic Description
(Default) Multiple selection isn't allowed.
Multiple items are selected or deselected by clicking them with the mouse or pressing the SPACEBAR.
Multiple items are selected by holding down SHIFT and clicking them with the mouse or by holding down SHIFT and pressing an arrow key to extend the selection from the previously selected item to the current item. You can also select items by dragging with the mouse. Holding down CTRL and clicking an item selects or deselects that item.

There may be occasions where you wish to clear the listbox selections, and if the list is large would like to complete this exercise automatically.

To add this functionality to a command button on your form you can use the following code (replace YourCommandButtonName and YourListBoxName with the names of your button and list box):

Private Sub YourCommandButtonName_Click()

    Dim varItm As Variant

    With YourListBoxName

        For Each varItm In .ItemsSelected
            .Selected(varItm) = False
        Next varItm

    End With
End Sub

Clicking the command button will now clear the listbox of any selected items.