Solved

Trying to setup a delete query in access based on results of another query.

Posted on 2012-03-16
7
290 Views
Last Modified: 2012-03-16
Here is my Delete query as of right now.
dltquery
I want to delete every row in the tblJobLog where tblJobLog.JobNum = qryJobLogDelCrit.jhJobNum.

Here is the sql for my current delete query;
DELETE tblJobLog.*
FROM tblJobLog INNER JOIN qryJobLogDelCrit ON tblJobLog.JobNum = qryJobLogDelCrit.jhJobNum


When I run this query as a Select query it will give me a list of JobNums that I would like to delete. I thought If I just changed it to a Delete query then it would delete those rows from tblJobLog.

When I try to run it I get the following error message;
Error
Thanks for the help!
0
Comment
Question by:SeyerIT
  • 3
  • 3
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 350 total points
ID: 37729480
Try this:

DELETE *
FROM tblJobLog
WHERE JobNum IN (SELECT jhJobNum FROM qryJobLogDelCrit)



It may also work without the *:

DELETE
FROM tblJobLog
WHERE JobNum IN (SELECT jhJobNum FROM qryJobLogDelCrit)
0
 
LVL 2

Author Comment

by:SeyerIT
ID: 37729489
Is that rerunning qryJobLogDelCrit for every record in tblJobLog? Seems like that may be the case because it just hangs.. Is there a quicker method by chance?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37729509
What is the SQL for qryJobLogDelCrit?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 150 total points
ID: 37729513
<Is there a quicker method by chance?>

create a table from the result of running qryJobLogDelCrit, name it tmpTable
( or change the qryJobLogDelCrit into a make table query)

then run this delete query

DELETE *
FROM tblJobLog
WHERE JobNum IN (SELECT jhJobNum FROM tmpTable)
0
 
LVL 2

Author Comment

by:SeyerIT
ID: 37729531
mbixup.. I'm sorry, I forgot to get all of my extra tables out of that query. qryJobLogDelCrit used to have a bunch of extra tables and calculations in it (I copied it from another table that had a bunch of stuff in it)

Once I deleted all the extra stuff from it, it ran almost immediately.

Thanks for the help there!

Thanks also Capricorn for your offering as well.. It would have solved the problem as well.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37729581
It sounds like you're set, but you probably could also work the criteria of qryJobLogDelCrit right into your delete query, to reduce it to a single query.  

That would be my preferred approach if the second query was not overly complex, and was where I was heading asking about the SQL
0
 
LVL 2

Author Comment

by:SeyerIT
ID: 37729587
Gotcha. Thanks again!
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

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.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

749 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