PC Review


Reply
Thread Tools Rate Thread

Delete Query - Delete matching records from 2 tables - Access 2000

 
 
Chris Stammers
Guest
Posts: n/a
 
      22nd Jan 2009
Hello,

I have a query to delete records that match from the 2 tables contained.
When I view the result of the query before running, it looks like it is going
to work however when I actually come to run it, I get the error 'Could Not
Delete From Specified Tables'. After reading the Help pages, I unchecked the
box 'Open Databases using record-level locking' from the Advanced Options tab
and this hasn't helped. Is it the case that I will need to close Access for
the tables to update before the query will run properly? Here is the SQL:
DELETE Retention.*, [Daily Check].policy, [Daily Check].[extracted on] AS
Expr1
FROM [Daily Check] INNER JOIN Retention ON [Daily Check].policy =
Retention.POLICY;

Many thanks.
Chris
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      22nd Jan 2009
Perhaps a subquery would do the trick:

DELETE FROM [Daily Check]
WHERE EXISTS
(SELECT policy
FROM Retention
WHERE Retention.Policy = [Daily Check].policy);

If subqueries are new, see:
http://allenbrowne.com/subquery-01.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Chris Stammers" <(E-Mail Removed)> wrote in message
news:F33C1A17-71B2-4C80-B216-(E-Mail Removed)...
> Hello,
>
> I have a query to delete records that match from the 2 tables contained.
> When I view the result of the query before running, it looks like it is
> going
> to work however when I actually come to run it, I get the error 'Could Not
> Delete From Specified Tables'. After reading the Help pages, I unchecked
> the
> box 'Open Databases using record-level locking' from the Advanced Options
> tab
> and this hasn't helped. Is it the case that I will need to close Access
> for
> the tables to update before the query will run properly? Here is the SQL:
> DELETE Retention.*, [Daily Check].policy, [Daily Check].[extracted on] AS
> Expr1
> FROM [Daily Check] INNER JOIN Retention ON [Daily Check].policy =
> Retention.POLICY;
>
> Many thanks.
> Chris


 
Reply With Quote
 
John Spencer (MVP)
Guest
Posts: n/a
 
      22nd Jan 2009
YOu can only delete records from ONE table at a time.

STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you
expect.

To delete records from Daily Check the query might look like
DELETE
FROM [Daily Check]
WHERE policy in (SELECT Policy From Retention)

To delete records from Retention the query would look like
DELETE
FROM Retention
WHERE policy in (SELECT Policy From [Daily Check])

You *MIGHT* be able to get this to work. Note that only one table is
mentioned in the DELETE clause.
DELETE DISTINCTROW Retention.*
FROM [Daily Check] INNER JOIN Retention
ON [Daily Check].policy = Retention.POLICY;


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Chris Stammers wrote:
> Hello,
>
> I have a query to delete records that match from the 2 tables contained.
> When I view the result of the query before running, it looks like it is going
> to work however when I actually come to run it, I get the error 'Could Not
> Delete From Specified Tables'. After reading the Help pages, I unchecked the
> box 'Open Databases using record-level locking' from the Advanced Options tab
> and this hasn't helped. Is it the case that I will need to close Access for
> the tables to update before the query will run properly? Here is the SQL:
> DELETE Retention.*, [Daily Check].policy, [Daily Check].[extracted on] AS
> Expr1
> FROM [Daily Check] INNER JOIN Retention ON [Daily Check].policy =
> Retention.POLICY;
>
> Many thanks.
> Chris

 
Reply With Quote
 
Chris Stammers
Guest
Posts: n/a
 
      22nd Jan 2009
Many thanks for your help. Your last option worked fine.

Regards,
Chris

"John Spencer (MVP)" wrote:

> YOu can only delete records from ONE table at a time.
>
> STEP 1: BACKUP your data before attempting the following.
> STEP 2: BACKUP your data before attempting the following.
>
> Without a backup you cannot restore the data if this does not work the way you
> expect.
>
> To delete records from Daily Check the query might look like
> DELETE
> FROM [Daily Check]
> WHERE policy in (SELECT Policy From Retention)
>
> To delete records from Retention the query would look like
> DELETE
> FROM Retention
> WHERE policy in (SELECT Policy From [Daily Check])
>
> You *MIGHT* be able to get this to work. Note that only one table is
> mentioned in the DELETE clause.
> DELETE DISTINCTROW Retention.*
> FROM [Daily Check] INNER JOIN Retention
> ON [Daily Check].policy = Retention.POLICY;
>
>
> John Spencer
> Access MVP 2002-2005, 2007-2009
> The Hilltop Institute
> University of Maryland Baltimore County
>
> Chris Stammers wrote:
> > Hello,
> >
> > I have a query to delete records that match from the 2 tables contained.
> > When I view the result of the query before running, it looks like it is going
> > to work however when I actually come to run it, I get the error 'Could Not
> > Delete From Specified Tables'. After reading the Help pages, I unchecked the
> > box 'Open Databases using record-level locking' from the Advanced Options tab
> > and this hasn't helped. Is it the case that I will need to close Access for
> > the tables to update before the query will run properly? Here is the SQL:
> > DELETE Retention.*, [Daily Check].policy, [Daily Check].[extracted on] AS
> > Expr1
> > FROM [Daily Check] INNER JOIN Retention ON [Daily Check].policy =
> > Retention.POLICY;
> >
> > Many thanks.
> > Chris

>

 
Reply With Quote
 
Chris Stammers
Guest
Posts: n/a
 
      22nd Jan 2009
Thanks for your help with this.

Regards,
Chris

"Allen Browne" wrote:

> Perhaps a subquery would do the trick:
>
> DELETE FROM [Daily Check]
> WHERE EXISTS
> (SELECT policy
> FROM Retention
> WHERE Retention.Policy = [Daily Check].policy);
>
> If subqueries are new, see:
> http://allenbrowne.com/subquery-01.html
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Chris Stammers" <(E-Mail Removed)> wrote in message
> news:F33C1A17-71B2-4C80-B216-(E-Mail Removed)...
> > Hello,
> >
> > I have a query to delete records that match from the 2 tables contained.
> > When I view the result of the query before running, it looks like it is
> > going
> > to work however when I actually come to run it, I get the error 'Could Not
> > Delete From Specified Tables'. After reading the Help pages, I unchecked
> > the
> > box 'Open Databases using record-level locking' from the Advanced Options
> > tab
> > and this hasn't helped. Is it the case that I will need to close Access
> > for
> > the tables to update before the query will run properly? Here is the SQL:
> > DELETE Retention.*, [Daily Check].policy, [Daily Check].[extracted on] AS
> > Expr1
> > FROM [Daily Check] INNER JOIN Retention ON [Daily Check].policy =
> > Retention.POLICY;
> >
> > Many thanks.
> > Chris

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating delete query based on matching fields between two tables DBGuy11 Microsoft Access Getting Started 1 24th Nov 2009 05:54 PM
How to delete certain records based on a column value on all tables in a 2003 Access database? Athena Microsoft Access 0 17th Jul 2007 11:37 PM
Delete Query of records in a table based on it's finding in two other tables Hendy88@gmail.com Microsoft Access 3 19th Feb 2007 10:08 PM
Delete matching records from two tables =?Utf-8?B?V29ybGRDVFplbg==?= Microsoft Access Queries 1 26th Jan 2007 08:49 PM
How to delete all records from tables in VBA wihout getting the confirm delete prompt ? Adrian Microsoft Access 4 16th Aug 2004 02:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:15 AM.