Delete Multiple Items in one Table

  • Thread starter Thread starter Sparky Arbuckle
  • Start date Start date
S

Sparky Arbuckle

I have searched for this but can't find any examples relevant to what I
am looking for. I have a web application that uses 2 listboxes so that
the user can transfer items that are to be deleted. Every item in the
listbox has the same ID. To put this in perspective, let's say that the
listbox contains all parts that make up a certain product. When only
one part is selected then I am able to delete just fine. When 2 or
more, 0 rows get deleted. I've tried this in access and can't find a
way to get it to work.

This works fine:
DELETE * FROM table WHERE ID = 23 AND (Part = "T-22H");

This does not work:
DELETE * FROM table WHERE ID = 23 AND (Part = "T-22H") AND (PartNumber
= "T-23H");

Any suggestions as to how to go about doing this?
 
In your example, is PartNumber actually the same field as Part?

If so, there will be no record in your table where the Part field is T-22H
and also T-23H at the same time. Did you mean to delete the records where
Part is either T-22H or T-23H:
DELETE * FROM table WHERE (ID = 23) AND ((Part = "T-22H") OR (Part =
"T-23H"));

If that's the idea, you might prefer to list the items like this:
DELETE * FROM table WHERE (ID = 23) AND (Part IN ("T-22H", "T-23H"));
 
The hardest part about this was building a string in the FOR NEXT. I
got it though!
 
Back
Top