clear button

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!
 
D

Dirk Goldgar

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
 
S

Sandra Teng

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.
 
D

Dirk Goldgar

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top