0
votes

I have a list box that I populate with a Table/Query and "select" multiple entries with a bit of VBA code. On Form_Current, I intend for the code to select whatever items in that listbox that are selected for the current record (saved in another table).

When I click to go to the next record, the previously selected list box items are still selected. How do I clear them? I would have thought a new record would do all of this for me automatically.

I'm just getting back into VBA for the first time in 12 years, so I'm no guru.

Thanks, Hans

1
Editing records with a listbox is a rather odd way to do things.David-W-Fenton

1 Answers

1
votes

Try this (found here):

Function ClearList(lst As ListBox) As Boolean
On Error GoTo Err_ClearList
    'Purpose:   Unselect all items in the listbox.
    'Return:    True if successful
    'Author:    Allen Browne. http://allenbrowne.com  June, 2006.
    Dim varItem As Variant

    If lst.MultiSelect = 0 Then
        lst = Null
    Else
        For Each varItem In lst.ItemsSelected
            lst.Selected(varItem) = False
        Next
    End If

    ClearList = True

Exit_ClearList:
    Exit Function

Err_ClearList:
    Call LogError(Err.Number, Err.Description, "ClearList()")
    Resume Exit_ClearList
End Function