empty listbox

kingsgambit

Registered User.
Local time
Today, 20:43
Joined
May 27, 2001
Messages
134
Is there a code to empty a listbox, I have two listboxes when a user selects from one listbox it runs a query and puts the result into another.
If they want to select again, I have to close and then open the form to clear the listboxes.
I found some code but that clears the highlighted item.
Me.[ListBoxName]=Empty
 
Create a button below the listbox and add this code to the On_Click event
Dim intX As Integer
For intX = 0 To ListBoxName.ListCount
Me.ListBoxName.Selected(intX) = False
Next intX
Me.Refresh 'not sure if this is needed though

HTH
 
If you are talking about absolutely clearing a listbox of a rowsource put a button on screen with this code:

Me.ListBox2.RowSource=""
Me.ListBox2.Requery

If the above suggestion does not meeting your requirements.
 
I have tried both suggestions above but,if you put rowsource="" it clears the query altogehter and then does not work.
The second idea removes what I selected.
What I wanted was to clear the result of the query from the list box so the user can select a new subject and the query result shown in the list box
 
Consider looping through all the options, if your list box is not too long, changing Me.ListBox.Selected(n) = False for all of them.

There's probably a more graceful solution, someone else may know.

HTH,
David R
 

Users who are viewing this thread

Back
Top Bottom