Delete Query Problem

Posted on 2008-06-16
Last Modified: 2013-11-05

I'm trying to create a query that would delete a record out of a table (NeedMethodsTable) if the record's specific fields (Invoice, Item) don't exist in a different query (InvoiceItems), and also if the record entered in is not more than 1 day old

This is what i have so far, but apparently the deletition of the record only works on the 1 day old part, but not the rest.

FROM NeedMethodTable
WHERE (Exists (SELECT [InvoiceItems].INVOICE, [InvoiceItems].ITEM  FROM  [InvoiceItems] WHERE (
      ((NeedMethodTable.Complete) Is Null Or (NeedMethodTable.Complete)<>-1)
AND ([InvoiceItems]![INVOICE] <> [NeedMethodTable.INVOICE])
AND ([InvoiceItems]![ITEM] <> [NeedMethodTable.Part Number])
Question by:repco
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2

Expert Comment

by:Joe Overman
ID: 21795246
Try this:

SELECT [needmethodstable]![Invoice] & [needmethodstable]![partnumber] AS [key], [needmethodstable]![date/time]>DateAdd("h",-24,Now())<>False AS Expr1
FROM needmethodstable
WHERE ((([needmethodstable]![Invoice] & [needmethodstable]![partnumber]) Not In (SELECT [invoiceitems]![invoice] & [invoiceitems]![item] AS [Key] FROM invoiceitems GROUP BY [invoiceitems]![invoice] & [invoiceitems]![item];) And [needmethodstable]![date/time]>DateAdd("h",-24,Now())<>False));

Expert Comment

by:Joe Overman
ID: 21795252
opps forgot the delete part:

DELETE needmethodstable.*, [needmethodstable]![Invoice] & [needmethodstable]![partnumber] AS [key], [needmethodstable]![date/time]>DateAdd("h",-24,Now())<>False AS Expr1
FROM needmethodstable
WHERE ((([needmethodstable]![Invoice] & [needmethodstable]![partnumber]) Not In (SELECT [invoiceitems]![invoice] & [invoiceitems]![item] AS [Key] FROM invoiceitems GROUP BY [invoiceitems]![invoice] & [invoiceitems]![item];) And [needmethodstable]![date/time]>DateAdd("h",-24,Now())<>False));

Accepted Solution

Joe Overman earned 500 total points
ID: 21795268
Darn typos (forget a space)

DELETE needmethodstable.*, [needmethodstable]![Invoice] & [needmethodstable]![part number] AS [key], [needmethodstable]![date/time]>DateAdd("h",-24,Now())<>False AS Expr1
FROM needmethodstable
WHERE ((([needmethodstable]![Invoice] & [needmethodstable]![part number]) Not In (SELECT [invoiceitems]![invoice] & [invoiceitems]![item] AS [Key] FROM invoiceitems GROUP BY [invoiceitems]![invoice] & [invoiceitems]![item];) And [needmethodstable]![date/time]>DateAdd("h",-24,Now())<>False));
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.


Author Comment

ID: 21795293
hi thank you for quick response but it gives me a syntax error

Expert Comment

by:Joe Overman
ID: 21795306
Check the field names I put in the query to make sure they match your database.

Author Comment

ID: 21795309
nevermind, had to put needmethodstable in brackets. it worked great! thanks!!!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question