Connecting Tech Pros Worldwide Forums | Help | Site Map

Select all Items in list box

P
Guest
 
Posts: n/a
#1: Nov 12 '05
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.



Dirk Goldgar
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Select all Items in list box


"P" <P@no_spam.com> wrote in message
news:fc3Ab.9316$aw2.4393101@newssrv26.news.prodigy .com[color=blue]
> 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.[/color]

'---- 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 ----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


MGFoster
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Select all Items in list box


P wrote:
[color=blue]
> 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.
>
>[/color]

Try:

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

--
MGFoster:::mgf
Oakland, CA (USA)

Greg Kraushaar
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Select all Items in list box


Try

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

instead
[color=blue][color=green]
>>SoabBox on[/color][/color]
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
[color=blue][color=green]
>>SoapBox off[/color][/color]

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)


On Fri, 05 Dec 2003 17:25:31 GMT, "P" <P@no_spam.com> wrote:
[color=blue]
>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.
>[/color]

Closed Thread