PDA

View Full Version : Check if a combination of field values exist in table, update if not.



Firepen
06-10-2020, 04:20 AM
Hi Guys, I'm having a little trouble with something.

I want to see if a combination of fields, say columns C+D, already exist as a combination in Columns A+B anywhere in the table (not just the same record.) If they do not, then I want to move the values from C&D over to A&B, if they do I would want to delete that record.

This is part of a data import and transformation module for tables that sit behind Cascade Combo Boxes, so currently the old data is in the A&B Columns and new data is in new records with data only in C&D (Data types do not yet match). I have pulled the unique combinations from the new data set out but some will match existing combinations.

Origianlly tried SQL EXISTS but this only checks the record, I suspect I need a Do Loop but not sure how to start with this query. Would appreciate any guidence.

Many Thanks,

Hightree
06-10-2020, 08:16 AM
Perhaps it is better that you show us what you already have, in that way we kan help better
:yes

OBP
06-10-2020, 08:48 AM
As Hightree says sample sample data would help a lot.
This would be tricky with queries alone as you would need both select and delete queries.
VBA that loops through the records with a second loop to test the rest would be required, ideally I would add a "delete" chckbox to the table that the loop could update where required and then run a delete query based on the delete checkbox to remove them after all the checks have been done.