Solved

Delete Query Problem

Posted on 2008-06-16
6
198 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
[X]
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
6 Comments
 
LVL 8

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));
0
 
LVL 8

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));
0
 
LVL 8

Accepted Solution

by:
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));
0
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 

Author Comment

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

Expert Comment

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

Author Comment

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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

688 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