Refer to listboxes using vba Array

  • Thread starter Thread starter John
  • Start date Start date
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?
 
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
 
Back
Top