We help IT Professionals succeed at work.
Get Started

How to highlight Access listbox with VBA function that passes listbox name and whether to highlight all or deselect?

stephenlecomptejr
on
748 Views
Last Modified: 2016-08-29
Please note code and sample - for some reason its not allowing me to highlight all items when I click a button.  Appreciate any explanation along with the sample fixed.

https://filedb.experts-exchange.com/incoming/ee-stuff/8157-sample_highlight.mdb

Thanks,
Stephen

P.S.  I did try sListBox as ListBox and it didn't work.   I'd rather be shown how to do it both ways - with as a string and a listbox.
Private Sub Highlight_Items(sListBox As String, bShow As Boolean)

  Dim varItem As Variant
  Dim myItem As String
    For Each varItem In Me.Controls(sListBox).ItemsSelected
          'do whatever here in the loop
        
        Me.Controls(sListBox).Selected(varItem) = bShow
        DoEvents
        
    Next varItem
    
    Me.Refresh

End Sub

Private Sub cmdSelAllSource_Click()
  Call Highlight_Items("lstVolume", True)
End Sub

Private Sub cmdUnSelAllSource_Click()
  Call Highlight_Items("lstVolume", False)
End Sub

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE