How to select all items in the listbox

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

Guest

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
 
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".
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top