Solved

Delete Query Problem

Posted on 2008-06-16
6
193 Views
Last Modified: 2013-11-05
Hi,

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.

DELETE *
FROM NeedMethodTable
WHERE (Exists (SELECT [InvoiceItems].INVOICE, [InvoiceItems].ITEM  FROM  [InvoiceItems] WHERE (
      ((NeedMethodTable.Complete) Is Null Or (NeedMethodTable.Complete)<>-1)
AND
((NeedMethodTable.[Date/Time])>DateAdd("h",-24,Now()))
AND ([InvoiceItems]![INVOICE] <> [NeedMethodTable.INVOICE])
AND ([InvoiceItems]![ITEM] <> [NeedMethodTable.Part Number])
))<>False);
0
Comment
Question by:repco
  • 4
  • 2
6 Comments
 
LVL 8

Expert Comment

by:masterjojobinks
Comment Utility
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));
0
 
LVL 8

Expert Comment

by:masterjojobinks
Comment Utility
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));
0
 
LVL 8

Accepted Solution

by:
masterjojobinks earned 500 total points
Comment Utility
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));
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:repco
Comment Utility
hi thank you for quick response but it gives me a syntax error
0
 
LVL 8

Expert Comment

by:masterjojobinks
Comment Utility
Check the field names I put in the query to make sure they match your database.
0
 

Author Comment

by:repco
Comment Utility
nevermind, had to put needmethodstable in brackets. it worked great! thanks!!!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now