Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select all button to select all items in multiple select listbox 2

Status
Not open for further replies.

northernbeaver

Programmer
Jul 9, 2001
164
0
0
CA
pretty straight forward question I have a listbox on a form. the form is unbound and the listbox has a rowsource set to a populated table and is showing the data fine. I want to create a command button on the form that when pressed will select all items in the list box so the user doesnt have to click every single one. not sure how to proceed
 
Try this ...

Assume the command button is called btnSelectAll, and the list box is lstTest.

Paste this code into the button's On_Click event:
Code:
Private Sub btnSelectAll_Click()

Dim I As Integer

For I = 0 To lstTest.ListCount
    lstTest.Selected(I) = True
Next I

DoEvents

End Sub

I hope that this helps.

Bob Stubbs
 
I'd replace this:
For I = 0 To lstTest.ListCount
By this:
For I = 0 To lstTest.ListCount - 1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top