Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 25

Thread: Solved: Listbox With Checkboxes inside

  1. #1
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location

    Solved: Listbox With Checkboxes inside

    Ive been searching the forum for code on how to have a list box and then have a check box next to the text within the listbox? Is this possible?

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Change your ListStyle to fmListStyleOptionn and your MultiSelect To fmMultiSelectExtended.

    Now, you should have CheckBoxes.

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I don't think so...but you can change the multiselect propterty of the listbox so they can select more than one item.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location
    [VBA]
    Private Sub Userform_Activate()

    With QueryListBox
    .AddItem "Query 1"
    .AddItem "Query 2"
    .AddItem "Query 4"
    .AddItem "Query 5"
    .AddItem "Query 6"
    .AddItem "Query 7"
    .AddItem "Query 8"
    .AddItem "Query 9"
    .AddItem "Query 10"
    .AddItem "Query 11"
    .AddItem "Query 12"
    .AddItem "Query 13"
    .AddItem "Query 14"
    .AddItem "Query 15"
    .AddItem "Query 16"
    End With[/VBA]

    My Listbox is not populating. Am I using the wrong event?

  5. #5
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    I pasted your code into my form, no problem.

  6. #6
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    If you don't change to fmMultiSelectExtended, you get Option boxes, not Check Boxes.

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    That works for me....in fact just plain multiselect works with it too for multiple selections.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    double check that the name of your lisbox matches QueryListBox

    activate code has to be in the userform code module
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Quote Originally Posted by lucas
    That works for me....in fact just plain multiselect works with it too for multiple selections.
    Lucas, you are correct. Probably using plain multiselect is a better choice (no need to hold control key or shift key)

  10. #10
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location
    With this code:
    [VBA]Private Sub Userform_Activate()

    With QueryListBox
    .AddItem "Query 1"
    .AddItem "Query 2"
    .AddItem "Query 4"
    .AddItem "Query 5"
    .AddItem "Query 6"
    .AddItem "Query 7"
    .AddItem "Query 8"
    .AddItem "Query 9"
    .AddItem "Query 10"
    .AddItem "Query 11"
    .AddItem "Query 12"
    .AddItem "Query 13"
    .AddItem "Query 14"
    .AddItem "Query 15"
    .AddItem "Query 16"
    End With [/VBA]
    The listbox briefly flickers and is empty.

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    why don't you post your workbook and this can be fixed easily I'm sure.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    this listbox is on a userform and not on a sheet correct?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  13. #13
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location
    Oops, it was on a worksheet. I feel stupid now.

  14. #14
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location
    Quote Originally Posted by lucas
    why don't you post your workbook and this can be fixed easily I'm sure.
    Like the actual file? or code?

    Its now under a workbook_open event. As soon as i open my excel sheet i see the list box populate then become empty. And the size of the list box get s bigger than what i set it when i designed it. How can i prevent this?

  15. #15
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    post the file....click on post reply at the bottom left of the last post..type your message then scroll down and look for a button that says manage attachments

    Your problem depends on several things...
    is the lisbox created from the forms toolbar or the visual basic toolbox...?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  16. #16
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location
    I drew the listbox on sheet1 using the control toolbar.

  17. #17
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Why is the workbook open event in a worksheet module?

  18. #18
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Set your listfillrange property for the listbox to AA1:AA3 as shown
    This is the easiest way....
    Workbook open code should go in the thisworkbook module and your public subs that are not command buttons should go in a standard module.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  19. #19
    VBAX Regular
    Joined
    Jun 2007
    Posts
    58
    Location
    Is there a way I can assign the items within the listbox using code? Using the way you gave me, can i still still get the index(i.e. 1,2,3) of the ones checked)

  20. #20
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Are you going to want to run a macro according to which ones are selected....because I don't think a listbox is the best way to do that..

    If you want to copy the text to a worksheet...yes.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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