Refer to listboxes using vba Array

J

John

I have several listboxes on a form
How can i refer to them using an array
ie.
Dim sctlList(5) As Controls (I've tried as ListBox and as string)
sctlList(0) = Me.list1
sctlList(1) = Me.list2
sctlList(2) = Me.list3
sctlList(3) = Me.list4
sctlList(4) = Me.list5

Then when I need to refer to a specific list...
ctlList=sctlList(n) 'where n is a integer that I set as needed
ctlList.ItemSelected
etc....
What am I doing wrong?
 
D

Dan Artuso

Hi,
These are objects and as such need to be 'Set'

Dim sctlList(1) As ListBox
Dim ctlList As ListBox

Set sctlList(0) = Me.List0
Set sctlList(1) = Me.lstFields

Set ctlList = sctlList(0)
MsgBox ctlList.Value
 

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