Delete records based on criteria (1 Viewer)

hllary

Registered User.
Local time
Today, 00:20
Joined
Sep 23, 2019
Messages
80
I'm trying to clean some records that have part numbers, category number, service type, and etc. I trying to write some vba that will delete a record based on two or more rows . The example below is scaled down. For every duplicate part number I want to delete the record if category1 and category are not 3 and 2. But if a part number does not have a category1 or category2 that are 3 and 2, then a keep the record that has 4 and 1.

Part_AssociatedCAGE_CodePartNumberCategory1Category2ServiceType
36627117X6775315000137258232DA
3662711945195315000137258232DS
ZZ-H-428813485315008414442452DA
28420-187B16568785315008414442431DS
LL1/4X3/4527935310005956211241DA
MS171657969065310005956211232DS
MS171688969065310005825677631DA
MS9048-104969065310005825677651DS

There are more conditions that need to be added but I'm can't figure out how to start this. For example is the category1 and category2 equal 3 and 2 for two or more records then delete the record that has DS. But sometimes there will be records with the same PartNumber and the servicetype will be DS for all of them.

A query will also work, one that selects the records based on the same criteria used to delete. I'm drawing a blank on figuring this out.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:20
Joined
May 7, 2009
Messages
19,230
based on what you wrote there are only 2 criteria:

delete * from your table where (([category1]=3 and [category2]=1) or ([category1]=4 and [category2]=1)) = False;
 

Users who are viewing this thread

Top Bottom