Automatically Highlight all items in a Multi Select List Box

  • Thread starter Thread starter Suzanne Lejeune
  • Start date Start date
S

Suzanne Lejeune

I have a multi select list box that in some cases I would like to highlight
all of the items in it. How would I do that? I thought I could run a macro
that would use SetValue to True or False. Something to that effect.

Thanks for your help.
suzanne
 
To de-select all items in a list box try: (I leave it you to figure out how
to select all.)
Dim lngX As Long

With Me![lstMyListBox]
For lngX = (.ItemsSelected.Count - 1) To 0 Step -1
.Selected(.ItemsSelected(lngX)) = False
Next lngX
End With
 
I'm a dummy! This works great to deselect. However, I thought by changing
False to True would have the opposite effect. It doesn't. Can you spell it
out for me what I need to change to select all?

Thanks
Suzanne

Joe Fallon said:
To de-select all items in a list box try: (I leave it you to figure out how
to select all.)
Dim lngX As Long

With Me![lstMyListBox]
For lngX = (.ItemsSelected.Count - 1) To 0 Step -1
.Selected(.ItemsSelected(lngX)) = False
Next lngX
End With

--
Joe Fallon
Access MVP



Suzanne Lejeune said:
I have a multi select list box that in some cases I would like to highlight
all of the items in it. How would I do that? I thought I could run a macro
that would use SetValue to True or False. Something to that effect.

Thanks for your help.
suzanne
 
To Select all Items in a Listbox:

Private Sub btnSelectAll_Click()
'You can use the Selected property to select items in a list box.
'For example, the following expression selects the fifth item in the list:
'Me!ListBox.Selected(4) = True

Dim lngX As Long

With Me![lstMyListBox]
For lngX = 0 To .ListCount
.Selected(lngX) = True
Next lngX
End With
End Sub

--
Joe Fallon
Access MVP



Suzanne Lejeune said:
I'm a dummy! This works great to deselect. However, I thought by changing
False to True would have the opposite effect. It doesn't. Can you spell it
out for me what I need to change to select all?

Thanks
Suzanne

Joe Fallon said:
To de-select all items in a list box try: (I leave it you to figure out how
to select all.)
Dim lngX As Long

With Me![lstMyListBox]
For lngX = (.ItemsSelected.Count - 1) To 0 Step -1
.Selected(.ItemsSelected(lngX)) = False
Next lngX
End With

--
Joe Fallon
Access MVP



Suzanne Lejeune said:
I have a multi select list box that in some cases I would like to highlight
all of the items in it. How would I do that? I thought I could run a macro
that would use SetValue to True or False. Something to that effect.

Thanks for your help.
suzanne
 
Back
Top