Change listbox to multiselect with code

merry_fay

Registered User.
Local time
Today, 01:02
Joined
Aug 10, 2010
Messages
54
Hi,

I have a listbox which needs to be set to None on the multiselect option when the user comes to select from it, BUT, if they make a selection from a different listbox, there may be several items in this one which need to be selected.

I think I've worked out the automatic selecting of the items in the second listbox, but I'm struggling to find the code to change it's multiselect settings from None to Simple (& then back again at the end of the code).

Can anyone help?

Thanks
:eek:
 
Set the multiselect property of the listbox to 1 for simple, or zero for none.
 
How? This is what I can't find the right VBA code to do.

It has to happen in the code or it will cause problems for other options.

Thanks
 
Me.Listboxname.MultiSelect = 1

or

Forms!FormName!ListBoxName.MultiSelect = 1
 
FYI, from Help:

This property can be set only in form Design view.
 
It appears so! Looks like I'll have to use the 2 list box hide/unhide toggle instead. I really didn't want to do that..........

Thanks for the help
:)
 
What you can do is simulate single multiselect.
Use the ListIndex to find out and record which item was clicked then loop through the control to deselect all items
reselect the one you had recorded.

i=ctl.ListIndex
for j=0 to ctl.ListCount-1
ctl.Selected(j) = False
next
ctl.Selected(i) = True
'or ctl.Selected(ctl.ListIndex) = True 'This way you don't even need to record the ListIndex
 

Users who are viewing this thread

Back
Top Bottom