Consulting

Results 1 to 3 of 3

Thread: Excel 2010 / VBA/ problem with code to create listbox in userform

  1. #1

    Excel 2010 / VBA/ problem with code to create listbox in userform

    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.







    Attached Images Attached Images

  2. #2
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello danieltur,

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

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  3. #3
    Quote Originally Posted by Leith Ross View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •