listbox on userform


Posted by xye on February 11, 2002 10:24 AM

hi

i was trying to do something like that 9excel 2000)
userform module

i putted listbox on form
and then added code like this :

dim lb as Object
...
...
set lb = ListBox1

then i was trying to make procedure

sub test( lbox as Object)
lbox.SetFocus
end Sub


when i was trying to call that function by typing
test(lb)
i get object required error

what am i doing wrong ?
please help
TIA
regards



Posted by Juan Pablo G. on February 11, 2002 11:51 AM

In an UserForm i put a Listbox, then tried this simple test

Private Sub UserForm_Click()
Dim Lb As MSForms.ListBox
Dim Lb1 As ListBox
Set Lb = ListBox1
MsgBox TypeName(Lb)

Set Lb1 = ListBox1
MsgBox TypeName(Lb1)
End Sub

As you SHOULD see, the first line should be Ok, and the second one causes an error. Why ? well, Excel has two types of listboxes, one of its own, the ListBox that you see in the Forms toolbar, which is "unique" to Excel, and the Control ListBox, which is a Form, available to all Office programs.

Hope that helps

Juan Pablo G.