PDA

View Full Version : Excel 2010 / VBA/ problem with code to create listbox in userform



danieltur
08-17-2018, 04:41 PM
Hi everybody,

I am a beginner with VBA, and need a little bit of help.

I am developing an application, in which I create checkboxes textboxes, comboboxes and listboxes.

I have a problem with the list boxes.


Here is my code:


Dim lecontrol As Control

Set lecontrol =userform1.controls.Add("forms.listbox.1", 1)

With lecontrol
.Top = dtopbx
.Left = leftoffset
.Name = "field" & huf- 1
.Width = dwidth
.SetFocus
End With

The result is the following: theUserForm displays the list of items, with a horizontal scrollbar and a verticalscrollbar, but there is no associated textbox zone, where the selectionnormally appears.
And I cannot select any item (please see attached picture).


If I replace in my code userform1.controls.Add("forms.listbox.1",1) with userform1.controls.Add("forms.combobox.1", 1), I create a"proper" Combobox, displayed and operating properly.

So, what's could be wrong with mycode?

Anybody?
Many thanks in advance for your kindhelp and your time.

Leith Ross
08-19-2018, 02:55 PM
Hello danieltur,

It may be the ProgID is case sensitive. Try using "Forms.ListBox.1" instead.

danieltur
08-20-2018, 01:00 AM
Hello danieltur,

It may be the ProgID is case sensitive. Try using "Forms.ListBox.1" instead.

good Morning, Leith.

thank you for your msg.

in fact I was totally mistaken. I thought it was possible to get a listbox similar in apparence to a combobox, with a text zone (only to show the selection), and a button on the right, to avoid the list to be displayed permanently.

what I do now is to use a combobox instead of a listbox, with the property .style set to 2. The combobox behavior is then similar to the listbox I meant to create.

again, many thks for your time and kind understanding.

Best rgds,
Daniel
Paris