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

x
?
Solved

delete records with SQL/VBA ACCESS

Posted on 2009-07-01
7
Medium Priority
?
551 Views
Last Modified: 2013-11-27
Hi,
I would like to know the SQL to delete all records in
TBL_CONTACT where TBL_USER.done = true

Structure of tables/query vs fields:

TBL_CONTACT             QRY_USER                TBL_USER
  userName   -------->  userName
                                       userId        -------->     userId
                                                                            done

             

DELETE *
FROM tbl_Contact
WHERE tbl_Contact.userName 
IN(select userName  from qry_User  ?????
     ??? where (qry_User.userId = tbl_User.userId,   tbl_User.Done=true);

Open in new window

0
Comment
Question by:Karl001
[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
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 24757215
I think this should do what you want. As always, test new code on a COPY of your database.

chuck
DELETE * FROM tbl_Contact WHERE tblContact.userName IN (SELECT userName FROM qry_User JOIN tblUser ON qry_User.userID = tbl_User.userID WHERE tbl_User.Done=True)

Open in new window

0
 

Author Comment

by:Karl001
ID: 24765536
It's doesn't work.
I have an syntax error message. I can't find where.

DELETE * FROM tbl_Contact
WHERE tbl_Contact.userName IN (SELECT userName FROM qry_User JOIN tbl_User ON qry_User.userID = tbl_User.userID WHERE tbl_User.Done=True)
0
 
LVL 16

Accepted Solution

by:
Chuck Wood earned 2000 total points
ID: 24765692
Try the subquery on its own.

chuck
SELECT userName FROM qry_User JOIN tbl_User ON qry_User.userID = tbl_User.userID WHERE tbl_User.Done=True

Open in new window

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 74

Expert Comment

by:Jeffrey Coachman
ID: 24765863
Something doesn't seem quite right.

Why is there a query between the two tables?
Are you saying that TBL_CONTACT and TBL_USER are not directly related?
Why not?

Perhaps I am not understanding something
This seems like a design issue.

Can you post the fields in these tables?

JeffCoachman
 
0
 

Author Comment

by:Karl001
ID: 24766729
Hi Jeff,

You are right, it's not a good design. But it's temporary, it is for merging data from old database to a new one, with a new structure.

Thanks,
Carol
0
 

Author Closing Comment

by:Karl001
ID: 31598883
I did the subquery. Now it's working,  I had to replace JOIN by INNER JOIN
Thanks,
Carol
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24770124
OK,

Looks like cwood-wm-com's got you covered.
;-)

JeffCoachman
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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.
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…
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…

610 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