Using a query to delete?

D

dabobson

Hi,
Suppose Tables B to F are all linked to Table A (with referential
integrity enforeced) through the field LinkCode (but not to each other
except through Table A).
I realize that tables C to F contain garbage for certain records, so I
want to delete those records from those tables, while leaving the
respective records in Tables A and B intact.
How can I do this without having to open each table C to F manually and
deleting the offending records?

I have tried using a query that includes all the fields from tables C
to F. This then allows me to go through each field one by one and
delete what is entered there - an improvement on the method above but
still very tedious. How can I clear all the values at once?
If I try to "Delete Record" Access tells me: "The record cannot be
deleted or changed because Table B contains related records." This
occurs even if I rerun the query without "Showing" any of the LinkCode
fields (ie the only fields that have any link with table B, through
Table A). Ideally I'd delete the entire record from tables C to F but a
solution which deletes all values other that LinkCode would be almost
as good.

Thanks for your help,
Doug
 
J

James Goodman

Add a column in Tables C to F, called DeleteRow. Set it as a yes no field.

Next, you need to create an update query & set the DeleteRow column to False
for all records. The set it to True for the records you want to delete.
Finally, create a delete query which is something like:
DELECT FROM tblF WHERE DeleteRow = True


This will then delete all records in that table with the DeleteRow column
set to true...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top