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

x
?
Solved

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

Posted on 2012-03-16
7
Medium Priority
?
309 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
[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
  • 3
  • 3
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 1400 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 600 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

Technology Partners: 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!

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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.

636 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