PDA

View Full Version : Solved: Referencing ListBoxes



MWE
01-29-2006, 02:46 PM
I have a Form with a dozen or so listboxes. When the form activates, the listboxes are filled with items from a worksheet. Aside from the particular listbox and the particular column of the worksheet, the item adds are identical. So, I created a variable ThisListBox of type ListBox, index across the worksheet columns setting ThisListBox = specific listbox using a Case construct and then sequence down the column. But VBA balks when it hits the first Set ThisListBox = statement (see code fragment below); so I must be doing something wrong.Private Sub UserForm_Activate()
Dim Col As Integer
Dim I As Long
Dim LastRow As Long
Dim ThisListBox As ListBox

For Col = 5 To 21 Step 2
Select Case Col
Case Is = 5 'date
Set ThisListBox = Me.lstbxDate

I know that I can get around this by typing ThisListBox as "object", but why does typing it as ListBox not work?

Thanks

Norie
01-29-2006, 03:18 PM
What's the actual error?

Try typing it as MSForms.Listbox.

Jacob Hilderbrand
01-29-2006, 03:20 PM
If you want it to be a User Form ListBox then...


Dim ThisListBox As MSForms.ListBox

MWE
01-30-2006, 02:23 PM
If you want it to be a User Form ListBox then...


Dim ThisListBox As MSForms.ListBox

Norrie/DRJ: Thanks for you replies

I thought that this was the likely problem, but could not remember what the prefix was. It is interesting that neither the Object Browser nor the inline editor pulldowns suggested that there were multiple types of ListBoxes.