Excel VBA - Accessing UserForm ListBox in the code

I've a user form with multiple listbox controls. I'm trying to access these listboxes through code but getting a "Type mismatch" error - not sure what I'm missing... any help?

    Dim lstListBox As ListBox
   
    Set lstListBox = frmManageSuites.lstReleases_AddSuite

Thanks.
DintapAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
Where are you accessing the code, in the UserForm module?

If so refer to it as Me.lstReleases_AddSuite, e.g.

Msgbox Me.lstReleases_AddSuite.Value

Open in new window


In code outside the UserForm module then use

UserForm Name. ListBox name e.g.

Msgbox frmManageSuites.lstReleases_AddSuite.Value

Open in new window

0
DintapAuthor Commented:
Thanks Roy. I'm able to access the value property using the direct reference to the listbox. But since I'm trying to write a generic module to manage multiple listboxes on the form (e.g. reset all listboxes), I'm trying to use a variable of ListBox but for some reason the assignment fails due to type mismatch.

    Dim lstListBox As ListBox
     
    Set lstListBox = frmManageSuites.lstReleases_AddSuite

Open in new window

0
Rgonzo1971Commented:
Hi,

pls try

Dim lstListBox As MSForms.ListBox

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DintapAuthor Commented:
Thanks Rgonzo1971. That obviously works :-)
0
Roy CoxGroup Finance ManagerCommented:
Best would be to write a Class module. John Walkenbach has a nice example to adapt

Example..

To clear the selections use

Dim oCtl As msforms.ListBox
For Each oCtl In Me.Controls
oCtl.ListIndex = -1 '/// no selection
Next oCtl

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.