clear button

  • Thread starter Thread starter Sandra Teng
  • Start date Start date
S

Sandra Teng

Hi,
I am having trouble writing the code for the clear button. I'd like to clear
button to clear all the selections in 3 of my listboxes when I click on it.
Thank you!
 
Sandra Teng said:
Hi,
I am having trouble writing the code for the clear button. I'd like to
clear
button to clear all the selections in 3 of my listboxes when I click on
it.


Are the list boxes multiselect or single-select?

If single-select, just set each list box's value to Nul:

Me.lstMyListbox = Null

If multiselect, you can use code like this for each list box:

Dim varI As Variant

With Me.lstMyListbox

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

End With
 
Hi,
Thanks for your help.
However, it gives me an error: Private Sub Clear_Click() was highlighted.
Here is the code:

Private Sub Clear_Click()
Dim varI As Variant

With Me.lstMyListbox

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

End With

End Sub



Thank you again.
 
Sandra Teng said:
Hi,
Thanks for your help.
However, it gives me an error: Private Sub Clear_Click() was highlighted.
Here is the code:

Private Sub Clear_Click()
Dim varI As Variant

With Me.lstMyListbox

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

End With

End Sub


You didn't say what the error message was, but ... Is "lstMyListbox" the
name of your list box? That's the name I used in my example code, but you
need to change that to the actual name of your list box.
 
Back
Top