Clearing list boxes

V

vanpar

I am wondering if it's possible to clear the contents of a list box. I want
to clear contents on the 'on click' command of another combo box on the same
form. Any suggestions?
 
D

Douglas J. Steele

What do you mean by "clear": empty it, or unselect any values that have been
selected?

To empty it, simply set its row source to an empty string.

To unselect selected values, you can use something like

Dim intLoop As Integer

For intLoop = 0 To Me!MyListBox.ListCount - 1
Me!MyListBox.Selected(intLoop) = False
Next intLoop
 
V

vanpar

I am looking to empty the list box whose row source is a query. For this
reason I am unable to set the list box's row source to an empty string. Is it
possible to empty the box another way? Thanks for your help!
 
D

Douglas J. Steele

If you've got a list box that derives its data from a query, then whatever
the query gives you is what should be in that list box. If you don't want
anything in the list box, then you no longer want the query to be its row
source.

There should be nothing stopping you from changing the row source in VBA
code. It's something like:

Me!MyListBox.RowSource = ""

(replace MyListBox with whatever your listbox is called)
 
Top