Solved

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

Posted on 2012-03-16
7
295 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 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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