Delete from a listbox.

  • Thread starter Thread starter Guest
  • Start date Start date
Change the WHERE clause in the listbox's RowSource.

This example shows how to exclude agencies 5 and 6 from the list box:

Me.[List0].RowSource = "SELECT AgencyId, AgencyName FROM tblAgency WHERE
AgencyId NOT IN (5, 6) ORDER BY AgencyName;"
 
if your listbox is based on table values then you can delete from the table
and then requery your listbox
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM TableName WHERE FieldName = '" &
ListBox.Column(0, ListBox.ListIndex) & "'"
ListBox.Requery
DoCmd.SetWarnings True
 
Thank you for your help. It loooks like it is trying to work but I get an
error: "Data type mismatch in criteria expresion"

The field in the table is an autonumber field. Is that a problem and how do
I fix it?
 
Thank you for your help. It loooks like it is trying to work but I get an
error: "Data type mismatch in criteria expresion"

The field in the table is an autonumber field. Is that a problem and how do
I fix it?
 
If the item in the listbox and table is numeric instead of text then change
the 1 line to
DoCmd.RunSQL "DELETE * FROM TableName WHERE FieldName = " &
ListBox.Column(0, ListBox.ListIndex)
 
Back
Top