Listbox

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

hello group.

I would like to delete items from a listbox by highlighting the item and
clicking delete.

Could someone offer assistance please?
 
Hi Chris,

The way to do this depends on the RowSourceType of the listbox.

Value list: write code that finds the relevant item in the list and
deletes it.

Table or query: depending on the situation either
-build and execute a SQL DELETE statement that deletes the relevant
record from the underlying table, then requery the combobox;
-modify the value of a field (probably a Yes/No field) in the underlying
table so the RowSource query no longer returns it, then requery the
combobox;
-modify the WHERE clause of a SQL RowSource so it excludes the record in
question.

Field list: you're unlikely to want to do that.
 
I guess that your listbox is based on a table and that by clicking Delete
you want to delete the record from the table and have the list box reflect
the change. In this case first you have to look up which item is selected in
the list box (use list.listindex to determine the row that is selected, or
List.ItemData(List.ListIndex) which results in the data that is selected),
then you have to look up the corresponding record in the table and delete it
using Recordset.Delete, finally you can refresh the data in the listbox
using List.Requery.

hope this puts you in the right direction.

Carl
 
Back
Top