View Full Version : Deleting Items from List Boxes


Dembrey
03-07-2002, 01:37 AM
This problem is driving me crazy since it should be straight forward.

I have a listbox "MyListBox" with RowSourceType = ValueList. The list is filled by the user selecting items from another bound listbox, this works OK by just appending the new item text to the RowSource string with an appropriate ";".

However, I would like to be able to delete an item from "MyListBox" when the user clicks on the item in the list he wants removed.

I've looked at the help and tried to use variously the RemoveItem method, Delete and Clear, None of which seem to work.

I think I can do it by manipulating the RowSource string to chop out the unwanted item using Instr(), Left(), Right(), etc. then reassign the string to RowSource and Requery the listbox. But this seems a very inelegant solution not to say slow.

Is there a one line command to remove a given item from a listbox?

Any help would be appreciated.

Alexandre
03-07-2002, 05:12 AM
Not to my knowledge.
If your listbox is based on a value list, I believe you are bound to do it through string processing. (methods for listboxes based on a table or query are not lighter anyway).

Alex

DJN
03-07-2002, 05:14 AM
There is an article on the Microsoft Knowledge base that may help. Just follow the link.
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q132026

David

Dembrey
03-07-2002, 05:45 AM
Thanks Alex/David.

String Chopping here I come.