Automatically Highlight all items in a Multi Select List Box

  • Thread starter Suzanne Lejeune
  • 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
 
J

Joe Fallon

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
 
S

Suzanne Lejeune

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
 
J

Joe Fallon

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top