Delete records using listbox

S

s4

Hi,
Does anyone know a way of deleting selected records in a multi-selection
list box?
Thanks
 
T

Tom van Stiphout

On Mon, 17 Dec 2007 08:19:00 -0800, s4 <[email protected]>
wrote:

There is no built-in way to do this, so you would have to write the
code yourself. Iterate over the SelectedItems collection, and call a
Delete query for each record.

Alternatively you can replace the listbox by a subform, which supports
automatic deletion.

-Tom.
 
D

Dale Fye

Assuming that the bound column of your listbox is a numeric value that
corresponds to an ID field in your table, you could write some code for a
command button. I strongly recommend you copy your data and work with the
backup until this is working the way you want it to.

Private Sub cmd_Delete_Selected_Click

Dim strSQL as string, varItem as variant

For each varItem in me.lst_ListName.itemsselected

strSQL = "DELETE * FROM tbl_yourTable " _
& "WHERE [ID] = " & me.lst_ListName.Column(0, varItem)
currentdb.execute strsql, dbFailOnError
Next

End Sub

HTH
Dale
 
Top