multiselect listbox

taniadimitri

Registered User.
Local time
Today, 08:21
Joined
Mar 13, 2007
Messages
17
What is an easy way of saving all the items selected in a multi-select
list box, especially so that I can revisit that form to see what I had selected earlier. I have been searching for code in google and got no luck. I would appreciate it if anyone can provide me the VBA code.

When I create the listbox should I make it as unbound field? Main form is based on one table. I want the selected values of a list box to get stored in this table and be able to retrieve back.

Thanks.
 
Last edited:
you could create a "temporary table" tblTemp to save the values you selected. if you want to save several previous views you will need a datetimesaved field and some way of knowing which datetime you want.
 
Here's how it is done. The table t_Items stores the information that populates the listbox. The field in that table named "Selected" determines whether or not the item is selected in the listbox. The form f_Listbox_Example shows how this works and had code to show you how I did it. Finally, the "Save Selections" button on the form will show you how to write the most recent selections on the fly. If you're not familiar with VBA, this may all seem confusing.

It's around 3:20am here, so there may be a better way to do this, but I know this works. It's simple once you get the basics. Look at the code and it should be clear what I'm doing (read the table when the form loads and select listbox items as necessary, and write out changes after clicking "Save Selections").

To directly answer you, the unbound listbox is a bad idea (see the example). You store the "selected" value in the table and use that in the form's OnLoad event to pre-populate the listbox's selections.

HTH
 

Attachments

Thank you so much for all your help. This is what exactly what I want. I have been searching for solution to this for long time. I was looking at google for the solution and I got confused by looking at the code as I have very basci VBA knowledge. But the above listbox example was simple to understand.

Thanks again.
 
Last edited:
Hi Moniker,

I got an issue with the list box I created by using your code.

The database I am working is an audit database. The audits are entered through entry form and can be edited through edit form. I have created the list box in the entry form and entered an audit (say audit1) by selecting the values of a list box as "Item0, Item2, Item4". I entered another audit (say audit2) by selecting the values of a list box as "Item1, Item3, Item5".

I went back to edit the audit1 and was surprised to see the values of a lsit box as "Item1, Item3, Item5" which were the values I selected in the audit2. This happens because the temporary items table holds the most recent values. Is there a way I can seen the original slected values of a listbox for individual audits. Please advise.

I appreciate all your help.

Thanks.
 

Users who are viewing this thread

Back
Top Bottom