Reset multiple listboxes

ekta

Registered User.
Local time
Today, 07:32
Joined
Sep 6, 2002
Messages
160
Hi,

I have 3 listboxes on my form. I want to reset them with one click. How can i do that?

Thanks,

Ekta
 
Figured it out.

Private Sub ClearListBoxes()
Dim i As Integer
Dim ctl As Control
Dim varItem As Variant
For Each ctl In Me.Controls
If ctl.ControlType = acListBox Then
For Each varItem In ctl.ItemsSelected
ctl.Selected(varItem) = False
Next
End If
Next
Set ctl = Nothing
End Sub
 
By the way, if these are single-select listboxes (the default) then you can just clear them like this:
Code:
Private Sub ClearListBoxes()
Dim ctl As Control

For Each ctl In Me.Controls
    If ctl.ControlType = acListBox Then
        ctl.Value=Null
    End If
Next
Set ctl = Nothing
End Sub

Also, you seem to have a "Dim i As Integer" just hanging out there.
 

Users who are viewing this thread

Back
Top Bottom