Link to home
Start Free TrialLog in
Avatar of iglink
iglinkFlag for Australia

asked on

Storing values from a multi select list box

I would like to be able to have a list of names in a list box, be able to select multiple names from the list box and then store them for later use on a report or for use in another list box.  I can create the multi select list box ok but then what?
Avatar of TWBit
TWBit
Flag of United States of America image

Permanently store them, or temporarily store them?

If just temporarily, you can just hide the form but still reference it for the report and other list box.  If you want to permanently store them, you will need to write the values to a table.
Avatar of iglink

ASKER

Yes permanently how do i write values to a table
You would need to have a table to hold the individual choices from the Multi-select list box.  These would be stored one choicve per record, along with the Id of the item to which the multiple choices 'belong'.  Can you give us some for description of precisely what you are trying to do.  What are the names relevant to?

AW
Why not have all the names in a table with the fields PName (text) and SelectedYN (YesNo).  When the form loads, all the names are in the listbox.  With multiselect on, the user makes several selections.  On the click of the cmdSaveSelected command button, the on click event runs two queries, one to set all SelectedYN fields to False and then use the ItemsSelected property to update the table.  Seem like a plan?
Avatar of Jeffrey Coachman
iglink,

"Store values"?

Let's say you have a list box that has a RowSource of:
SELECT tblCustomers.CustomerID, tblCustomers.CompanyName FROM tblCustomers
So it lists all your customers.
You have set the "MultiSelect" Property of this listbox to "Extended"

Now, you want to be able to select multiple customers, and generate a Report using only the selected Customers.
Correct?

You don't technically "Store" the values.
You use code to "Accumulate" the selections, then build an SQL string that can be used as the Reports Record Source. (or you can modify it to be the source of anything you like)

I present you with my Sample, I use this as the basis for all my Multi-select List box Report menus (and as a teaching tool).
(It has comments all over the place!)
;)
https://filedb.experts-exchange.com/incoming/ee-stuff/5933-Access--EE-Q22994575--MultiSele.zip

I adopted it oh so many years ago from this seminal link.
http://www.mvps.org/access/reports/rpt0005.htm

Hope this helps!
:)

JeffCoachman
I had a look Jeff, nice work, but it doesn't 'store the values'.  As I said before, the easiest way I could think of was to add a field to the table, and check off the boxes like you retreived the 'selected' customers in the form.
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jeff said:  I just figured that they might not really need to stored the selections, just "Use" them.

but iglink said earlier:  Yes permanently how do i write values to a table.

I was just trying to kill two birds with one stone - a single table to populate the listbox, and be able to use the same table to 'store' the selected values until you wanted another set.  

iglink:  If you need to 'store' the selected values for just the life of the form, Jeff's will do it.  If you need to store the set until you generate a new set, mine is a solution.  If you need to store each set permanently, with some other key to be able to distinguish between sets, you do not yet have a solution.  What is it?
Avatar of iglink

ASKER

well i think its a bit of both - I have a list of all employees in a company which will appear in the first list. I want to be able to select on employees in that list  that say come to a meeting ie attendiees or who appologise for not coming so there would be three columns one for name, on for attendance one for appology ie where the last two are check boxes.  Then the names that are selected with attendiese checked are transfereed to another list for use during the meeting to assign names to comments.  But at any time in the future if you want to print reports then a list of attendies and apploogies ie from the check boxes would be printed so thats the stored bit. - I havent had a good look through the code yet but what do you recommend now?  Also is it possible to get the check box thing working in a multi select list?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial