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?
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?
Change your ListStyle to fmListStyleOptionn and your MultiSelect To fmMultiSelectExtended.
Now, you should have CheckBoxes.
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
[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?
I pasted your code into my form, no problem.
If you don't change to fmMultiSelectExtended, you get Option boxes, not Check Boxes.
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
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
Lucas, you are correct. Probably using plain multiselect is a better choice (no need to hold control key or shift key)Originally Posted by lucas
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.
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
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
Oops, it was on a worksheet. I feel stupid now.
Like the actual file? or code?Originally Posted by lucas
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?
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
I drew the listbox on sheet1 using the control toolbar.
Why is the workbook open event in a worksheet module?
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
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)
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