Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with getting code to work

Status
Not open for further replies.

melaniews

Technical User
Oct 14, 2002
91
US
I'm trying to make it easy for a user to select all in a listbox.

This code works great for clearing all selections (lboTPromoID.Selected(varItem) = False). Why doesn't it work to select all when (varItem) = True?

Also, how can I accomplish my goal here?


Private Sub cmdSelectAll_Click()
On Error GoTo Err_cmdSelectAll_Click

'set a select all command here

Dim varItem
For Each varItem In lboTPromoID.ItemsSelected
lboTPromoID.Selected(varItem) = True
Next varItem

Exit_cmdSelectAll_Click:
Exit Sub

Err_cmdSelectAll_Click:
MsgBox Err.Description
Resume Exit_cmdSelectAll_Click
End Sub


TIA,
Melanie
 
The reason it works for clearing the selection is because you're only selected the selected items

For Each varItem In lboTPromoID.ItemsSelected

To select all of the items in a list box, I use the following code:
Code:
   Dim lCtl_CntrlSource       As Control
   Dim lInt_CurrRow           As Integer
   
   Set lCtl_CntrlSource = [Forms]![frmReportsMain]![lstReportList]
   For lInt_CurrRow = 0 To lCtl_CntrlSource.ListCount - 1
      lCtl_CntrlSource.Selected(lInt_CurrRow) = True
   Next lInt_CurrRow
And it's very easy to change True to False to Unselect them all, but that is not an issue here.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks Cajun

It works great! and is useful in other areas as well.

Thanks,
Melanie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top