Select All in a list Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How would I code a user to select every record in a list box either by a
selection or by a check box?

For example if there is a list box that has 5 records, I would liek the user
to obe able to either check a box or have an option to select all and have
all of the items in the list box selected.


I know this has to do with looping and using ListCount in some regards but
I am not sure as to the context of how to use it.

THanks fo ryour help.
Chad
 
To select or unselect each item in the list box based on the value of say a
checkbox:

Dim lngItem As Long
Dim blnSelect As Boolean
blnSelect = Me.CheckBoxName.Value
For lngItem = 0 - me.ListBoxName.ColumnHeads To _
Me.ListBoxName.ListCount - 1
Me.ListBoxName.Selected(lngItem) = blnSelect
Next lngItem
 
Code like this behind a command button or the after update event of a check box should suffice:

Dim lngX As Long

With Me.lstMyListBox
For lngX = Abs(.ColumnHeads) To (.ListCount - 1)
.Selected(lngX) = True
Next
End With

(Replace lstMyListBox with the actual name of your listbox)
 
What I do is to leave the list box blank to select all
records. To accomplish this in your criteria in your query
put:

Like Forms![Formname]![list Box name] & "*"

Jim
 
Back
Top