Change to MultiSelect by code

M

Martin

Hello,

I have the following code:

Forms("MainMenu").Controls("MyList").MultiSelect = 2

I want to convert it to a multi select if the user wants to however I get an
error box saying I cant assign a value to this object (which is a list box).

Can anyone help?

Thanks in advance

Martin
 
R

ryguy7272

Take a look at this:
http://www.fontstuff.com/access/acctut11.htm

It may be simpler than you think. If you go into Design View, click
Properties, then click All, Multi Select, Simple. go back to Form View and
try it. That will allow a user to click several items in the ListBox. Multi
Select, Extended will allow a user to click multiple items by holding down
the Ctrl key and clicking items with the mouse.
 
F

fredg

Hello,

I have the following code:

Forms("MainMenu").Controls("MyList").MultiSelect = 2

I want to convert it to a multi select if the user wants to however I get an
error box saying I cant assign a value to this object (which is a list box).

Can anyone help?

Thanks in advance

Martin

Are you sure you wish to allow the user to change this property?
While the form is open? Using code?
While the form is open, you need to also open the form in design view.
Make the change.
Close the chanvged form and save the changes.
Then re-open the form in Form View.

Code a command button's Click event:

DoCmd.Echo False
DoCmd.OpenForm "FormName", acDesign, , , , acHidden
Forms!FormName!ListBoxName.MultiSelect = 2
DoCmd.Close acForm, "FormName", acSaveYes
DoCmd.OpenForm "FormName"
DoCmd.Echo True

Are you aware that you will need to use code to read and do something
with the multi selected values in the List Box?
 
S

Stuart McCall

Martin said:
Hello,

I have the following code:

Forms("MainMenu").Controls("MyList").MultiSelect = 2

I want to convert it to a multi select if the user wants to however I get
an
error box saying I cant assign a value to this object (which is a list
box).

Can anyone help?

Thanks in advance

Martin

It's not possible to change a listbox's multiselect property at runtime. You
can only do this when the form is open in design view.

That said, there is a workaround: Create another listbox with the same
dimensions as your original. Set the multiselect property appropriately and
the visible property to No/False. Position this new listbox directly
covering the other one. When you want to change to multiselect mode, hide
the original listbox (Me.ListboxName.Visible = False) and show the new one.
To go back to no multiselect, reverse the process.
 
J

John W. Vinson

Hello,

I have the following code:

Forms("MainMenu").Controls("MyList").MultiSelect = 2

I want to convert it to a multi select if the user wants to however I get an
error box saying I cant assign a value to this object (which is a list box).

Can anyone help?

Thanks in advance

Martin

You can only change the properties of a listbox in Design view; it sounds like
you're trying to change it on the fly while the form is open. I don't believe
that you can do so.

What's the context?
 
L

Linq Adams via AccessMonster.com

And everything else aside, the way in which you handle selection(s) made from
a Multi-select Listbox is different from the way in which you handle
Listboxes with Multi-select set to No. A Multi-select Listbox, for instance,
has no Value Property!

Having it Multi-select. After all, this doesn't prevent the user from making
a single selection.
 
J

JimBurke via AccessMonster.com

As if you don't have enough replies already! But another way to do it, if you
really have to allow them to choose whether multiple selections are allowed,
is just check the ItemsSelected.Count property when they go to process the
list. if they're only allowed to select one item (and I would think there
would be an indicator somewhere on the form that's telling them this) and
ItemsSelected.Count is > 1, just give them an error message telling them they
can only select one.
 
D

Dirk Goldgar

Martin said:
Hello,

I have the following code:

Forms("MainMenu").Controls("MyList").MultiSelect = 2

I want to convert it to a multi select if the user wants to however I get
an
error box saying I cant assign a value to this object (which is a list
box).

Can anyone help?


As others have said, you can't change the list box's MultiSelect property at
run time. I believe you could use code in various events to make a
multiselect list box behave like a single-select list box, depending on a
flag you'd set.
control.
 
M

Martin

Thank you all for your replies, certainly a few things to think about.

Stuart - I am going to take your approach, seems the best work around and
will look seemless for the user.

Many thanks

Martin
 
S

Stuart McCall

Martin said:
Thank you all for your replies, certainly a few things to think about.

Stuart - I am going to take your approach, seems the best work around and
will look seemless for the user.

Many thanks

Martin

I meant to say in my previous that the downside to the technique is that you
must fill both lists when the form loads, unless they're fast enough to fill
at the time you switch.

Also it may be worth changing some attribute of the multiselect list, like
the backcolor, or font, so the user knows which one he/she is looking at.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top