PC Review


Reply
Thread Tools Rate Thread

Change to MultiSelect by code

 
 
Martin
Guest
Posts: n/a
 
      26th Feb 2010
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
 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      26th Feb 2010
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.


--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Martin" wrote:

> 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

 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      26th Feb 2010
On Fri, 26 Feb 2010 07:38:05 -0800, Martin wrote:

> 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?


--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
Stuart McCall
Guest
Posts: n/a
 
      26th Feb 2010
"Martin" <(E-Mail Removed)> wrote in message
news:476007EA-9923-4C59-90F1-(E-Mail Removed)...
> 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.


 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      26th Feb 2010
On Fri, 26 Feb 2010 07:38:05 -0800, Martin <(E-Mail Removed)>
wrote:

>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?
--

John W. Vinson [MVP]
 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      26th Feb 2010
"Martin" <(E-Mail Removed)> wrote in message
news:476007EA-9923-4C59-90F1-(E-Mail Removed)...
> 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.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 
Reply With Quote
 
Martin
Guest
Posts: n/a
 
      1st Mar 2010
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

"Stuart McCall" wrote:

> "Martin" <(E-Mail Removed)> wrote in message
> news:476007EA-9923-4C59-90F1-(E-Mail Removed)...
> > 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.
>
>
> .
>

 
Reply With Quote
 
Stuart McCall
Guest
Posts: n/a
 
      1st Mar 2010
"Martin" <(E-Mail Removed)> wrote in message
news:B8AB5F60-A1BE-4BF2-B9E7-(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Problem with multiselect list box code Douglas J. Steele Microsoft Access Form Coding 2 5th Jan 2007 07:46 AM
Setting MultiSelect in code =?Utf-8?B?TWlrZSBHb3J2b2thag==?= Microsoft Access Forms 2 5th Dec 2005 08:01 PM
MultiSelect List code =?Utf-8?B?U2hlbA==?= Microsoft Access Form Coding 3 25th Mar 2005 04:11 PM
multiselect listbox code =?Utf-8?B?U2hlbA==?= Microsoft Access VBA Modules 2 3rd Mar 2005 10:25 PM
Multiselect listbox code using IN operator =?Utf-8?B?SmltIEdyZWVuZQ==?= Microsoft Access Form Coding 3 26th Nov 2004 07:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:45 PM.