How to select all items in the listbox

G

Gabriel

Hi,

I have a listbox where the value will cange based on parameter I select from
a combo box using after_update event in the combo box.
Is there a way to select all items in the listbox each time the value
changes ?
The idea is that users will select almost 80% from the available value in
the listbox.

TIA
Gabriel
 
D

Dirk Goldgar

Gabriel said:
Hi,

I have a listbox where the value will cange based on parameter I
select from a combo box using after_update event in the combo box.
Is there a way to select all items in the listbox each time the value
changes ?
The idea is that users will select almost 80% from the available
value in the listbox.

TIA
Gabriel

Presumably it's a multiselect list box. Here, this code will do it:

Dim lngX As Long

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

Substitute your own list box's name for "lstMyListBox".
 
A

Allen Browne

You can loop through the items in the listbox, and set the Selected
property, but where is this headed?

Generally, you don't want to use a multi-select listbox with a bound field,
so I'm assuming this is unbound. Typically you end up with something like:
[MyID] IN (1,2,4,6,7,8,9)
Would it be more efficient for the user and for Access to use:
[MyID] NOT IN (3, 5)
i.e. to exclude the items that the user selected?

If that idea is a bit cryptic, there's an example in:
Use a multi-select list box to filter a report
at:
http://members.iinet.net.au/~allenbrowne/ser-50.html

You could even provide a combo box where the user selects whether the user
wants to Include or Exclude the items selected in the listbox.

BTW, the user may expect the behavior:
([MyID] NOT IN (3, 5)) OR ([MyID] Is Null)
 
Top