I have a list box and I want to be able to clear the selected items programmatically. Has anyone ever done this before with out setting he rowsource of the listbox to "" the resetting the rowsource? Is there another way to do this?
I've found that the ActiveX control "Microsoft Forms 2.0 ListBox" it much easier to perform what you want. It's pretty easy to add and remove items from this type of list box. For help on using this ActiveX control, check out fm20.hlp on your hard drive.
Depends on what you mean. If you mean to deselect them you can use:
Dim i As Integer
For i = 0 to Me!YourListBox.ListCount-1
Me!YourListBox(i).Selected = False
Next i
If you mean to remove them from the list, then it depends on the rowsource of the list box. For a value list you can use the following:
Dim varRow As Variant
Dim lngPos As Long
Dim lstBox As Control
Set lstBox = Me!YourListBox
For Each varRow in lstBox.ItemsSelected
lngPos = InStr(lstBox.RowSource, lstBox.Columns(0, varRow)
lstBox.RowSource = Left(lstBox.RowSource, lngPos - 2) &
Mid(lstBox.RowSource, lngPos + Len(lstBox.Columns(0, varRow))
Next VarRow
If you RowSource is a query or sql then you need some way of identifying what belongs in the list box and change the record on the table accordingly or replace the sql if that seems necessary.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.