PDA

View Full Version : UserForm clear controls



yn19832
04-02-2007, 02:45 AM
I have a UserForm. which contains a listbox named ListCountry and it allows multi-selection. After selecting items and add it to another listbox, I want to clear the controls. How can I do that?

Many many thanks.

Bob Phillips
04-02-2007, 02:59 AM
Me.ListCountry.Clear

yn19832
04-02-2007, 03:10 AM
I am sorry I did not describle it clearly. I do not want to clear the items in the listbox, I just want to unselect the items I have selected, so I can enter new selection.

Thanks a lot.

fumei
04-02-2007, 03:52 AM
I think you have to iterate through the list, making Selected = False.Dim j As Long
For j = 0 To ListBox1.ListCount
ListBox1.Selected(j) = False
Next

There may be a better way, but explicitly making the items false certainly clears the selected status.

Aussiebear
04-02-2007, 04:05 AM
If you just want to clear the selection from the listbox, then give XLD's suggestion a go.

Bob Phillips
04-02-2007, 04:55 AM
Just select anew, the previous selection goes.

moa
04-02-2007, 06:22 AM
Depends on which mode of multiSelect is set for the listbox. Sounds like it is fmMultiSelectMulti mode in this case. If it is then Fumei's suggestion is the only way to go as far as I know.

Norie
04-02-2007, 06:57 AM
As far as I'm aware the only way to this is fumei's suggestion.

I used to hope this would work but it doesn't for a multiselect.

ListBox1.ListIndex = -1

yn19832
04-02-2007, 07:17 AM
Thanks a lot for all of you.

I tried sth like fumei's and it did work.