Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete Query Problem

Posted on 2008-06-16
6
Medium Priority
?
200 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 2000 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

596 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