Select all Items in list box

  • Thread starter Thread starter P
  • Start date Start date
P

P

Hi,

Access 2002. I created a list box with multiselect set to extended. I would
like to offer a command button that selects all items for the user. I am
trying:
For each varItem in lstAccounts
lstAccounts.Selected(varItem) = True
Next varItem

I am getting run-time error 438: Object doesn't support this property or
method. Any suggestion? Thank you. P.
 
P

use (to Select an Item)
For i = 0 to lstAccounts.listcoun
lstAccounts.Selected(i) = Tru
Next

use (to Deselect All Items)
For each varItms in lstAccounts.ItemsSelecte
lstAccounts.Selected(varItms) = fals
Next

HT

----- P wrote: ----

Hi

Access 2002. I created a list box with multiselect set to extended. I woul
like to offer a command button that selects all items for the user. I a
trying
For each varItem in lstAccount
lstAccounts.Selected(varItem) = Tru
Next varIte

I am getting run-time error 438: Object doesn't support this property o
method. Any suggestion? Thank you. P
 
P said:
Hi,

Access 2002. I created a list box with multiselect set to extended. I
would like to offer a command button that selects all items for the
user. I am trying:
For each varItem in lstAccounts
lstAccounts.Selected(varItem) = True
Next varItem

I am getting run-time error 438: Object doesn't support this property
or method. Any suggestion? Thank you. P.

'---- start of code ----
Private Sub cmdSelectAll_Click()

Dim lngX As Long

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

End Sub

'---- end of code ----

And our special offer today: code to unselect all!

'---- start of code ----
Private Sub cmdClearSelections_Click()


Dim lngX As Long

With Me.lstAccounts

For lngX = (.ItemsSelected.Count - 1) To 0 Step -1
.Selected(.ItemsSelected(lngX)) = False
Next lngX

End With

End Sub
'---- end of code ----
 
P said:
Hi,

Access 2002. I created a list box with multiselect set to extended. I would
like to offer a command button that selects all items for the user. I am
trying:
For each varItem in lstAccounts
lstAccounts.Selected(varItem) = True
Next varItem

I am getting run-time error 438: Object doesn't support this property or
method. Any suggestion? Thank you. P.

Try:

For intCurrentRow = 0 To lstAccounts.ListCount - 1
lstAccounts.Selected(intCurrentRow) = True
Next intCurrentRow
 
Try

For i = 0 To Me.ListAccounts.ListCount - 1
Me.ListAccounts.Selected(i) = True
Next

instead
However If you are using the listbox to build a query
Select....Where item in (..,,.,.)

You may be better off using a check box buttonto set a flag so that
the query builder removes the here clause altogether, or if you are
using a parameter in a saved query, use a second query..
The way I usually construct these is to put a dummy entry at the top
of the list box
(All) and sometimes
(Any)
Depending on how I am building my criteria. These use flags in the
code behind them to use more efficient queries. for special cases

HTH
Regards Greg Kraushaar
Wentworth Falls Australia
(Do not email - the reply address is a Spam spoofer)
(If you really must, remove all UCase and numbers)
 
Back
Top