Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add/Remove Items from Listbox

Status
Not open for further replies.

spiralmind

Technical User
Aug 20, 2002
130
US
I am currently building a form to be used to allow users to add records to and remove records from a table (to be used as a more maintainable manner of defining relatively static query criteria than asking the users to directly edit a set of SQL statements). I would like to achive this by displaying a textbox, two listboxes, and three command buttons.
The textbox is to be used to enter a new item to add to the list, and will have an "Add to List" button to accompany it. The first listbox will hold all items currently in the list, and the second will hold any that the user has decided to remove (to allow the user to restore a value that they had mistakenly pulled from the first list). Between these two listboxes there will be two more buttons "Remove from list" and "Restore to List".
The challange I am facing is how to fill the first list (without locking it or binding it directly to the table it references), and how to add/remove items in each list through code written into the buttons' onClick events. Any help will be greatly appreciated as I have spent much time looking for an answer or suitable example and have not yet been able to locate one.

- Thankyou, Christian



 
an update on this one:

in access 2002 (maybe 2000 as well), there are "additem" and "removeitem" methods for a listbox.

in access 97 you can either rewrite the entire rowsource of either listbox by filling them from arrays and calling off items from those arrays when they need to be removed or inserted, or (i chose this one even though i'm working in ac2002) by using a table with every item that could be in either list (which is known and fixed upon opening the form, though it could be modified with recordsets or a little SQL embedded in the code somewhere to append any truely "new" items) and a yes/no field. if it's marked "yes" it's in one box, if it's marked "no" it is in the other, and items are moved back and forth by switching the item's state in the table through the code attached to the left/right arrow buttons i used in this form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top