Link to home
Start Free TrialLog in
Avatar of michael1174
michael1174Flag for United States of America

asked on

Select and deselect multi select listbox in Access

Experts,

Right now, I am running the following code to either select or deselect all rows in the mult select listbox. Sometimes the listbox contains many values and there is a several second delay when running this code.  I was wondering if there was a quicker way to select or deselect all rows in the listbox?

Thanks!

For index = 1 To Me.lstStringID.ListCount
    Me.lstStringID.Selected(index - 1) = False
Next index

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of michael1174

ASKER

ok, that is much better for deselecting... anyone else have any tricks for selecting?
That's funny. Believe it or not, I have never thought of that until RIGHT NOW! And I've got many places where I use MSLB's with Select All and Select None buttons.  Looks I will be modifying some code.

Again, how many list items worst case here ?

mx
hey, just like they say, you learn something new everyday!

anyway, i have these counts and i am listing the "products" in the listbox:

ProductID      CountOfProductID
1      800
2      101
3      1463
4      441
5      3932
6      2135
Sorry, I'm not clear on the number of list box items (max) at one time?

Also ... I've tried various ways to speed up Select All, but haven't had much success.  It's  pretty much a limitation of the list box control.

mx
This might work also:

Me.YourListBoxName.RowSource = Me.YourListBoxName.RowSource
to select all items in listbox

With Me.List0
    For j = 0 To .ListCount - 1
        .Selected(j) = True
    Next
End With

to deselect all

With Me.List0
    For j = 0 To .ListCount - 1
        .Selected(j) = false
    Next
End With
MX,

I guess the limit is about 65000, beyond that one needs to use a UserDefineFunction.
eghtebas - I am asking him how many he has ... that the max possible.

mx
mx,

Thanks. But it could be read both ways.
I meant  "NOT the max possible" ... typo

mx
I have a combo box controlling the listbox, so I was giving the max per product.  So, the max would be 3932 rows.
That's a LOT of rows.  Not sure you are going to be able to significantly improve the Select All with that many rows!

I personally fell that is way beyond the original intent of a list/combo box.

mx
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
JEFF .... long time no see !!! Happy Ho to you.  Hope you get out this way some day.

joe
To select All, in my listbox I added a row called "All" for the first row in my listbox.  I put in "All" by adding a union to the underlying row source query such as:

select "*" AS ID, "(All)" AS description
from tblProduct
union
select ProductID, Product
from tblProduct
OrderBy Description


Thanks..