Select all in List box

MarionD

Registered User.
Local time
Today, 20:39
Joined
Oct 10, 2000
Messages
425
Hi all,

I know this must be easy but I just can't do it!

I have a multi select list box on a form. All I want to do is add a button saying "select all" and I want all the items to be selected (like Ctrl A in a Form)

Would really appreciate any help!

Marion
 
Private Sub Command5_Click()
Dim i As Integer
For i = 0 To Me.List2.ListCount
Me.List2.Selected(i) = True
Next i
End Sub
 
Stick this in a module:

Code:
Public Sub SelectAll(ByVal lst As ListBox)

    Dim intCounter As Integer
    
    For intCounter = 0 To lst.ListCount - 1
        lst.Selected(intCounter) = True
    Next intCounter

End Sub



On your button's click event you can just put:

Code:
Call SelectAll(Me.lstMyListBox)

where lstMyListBox is the name of your listbox.



You can call this sub to do more than one listbox in your database.
 
Thank you so much !
Easy when you know how isn't it!

Bye for now
Marion
 

Users who are viewing this thread

Back
Top Bottom