473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to Delete selected data in one table by referencing another table info

I have an ms access database in which there exit two(2) tables thus tblstudents and tbltrans. The field ID is common to both tables whereas boarder is the criteria and referencing field in tblstudents that I want to use.

Now, I want the system to delete only the selected students in the tbltrans table base on the criteria boarder. Below is the code I used but not working well for me. plse help me

strSQL = "Select * from students where Level BETWEEN " _
& """" & LL & """ and """ & UL & """ and boarder = '';"
DoCmd.RunSQL strSQL

strSQL1 = "DELETE from rstrans (select * from strSQL where " _
& "(((rstrans.trans_code) in ('219')));"
DoCmd.RunSQL strSQL1
Mar 9 '14 #1
2 1015
GKJR
108 64KB
Those queries don't really make sense to me. I don't think you need two different queries either. I'm assuming you have all of your variables defined and all of your table and field names are spelled correctly.

Use the query design grid to make a query that selects the records you need. You can use more than one field to filter the results.

Go to the SQL view of the query and copy the code.

Paste it into you VBA editor where you want it. You can create a string variable to hold the code or you can just execute it as is.

Change the "SELECT" to "DELETE" and use DoCmd.RunSQL similar to what you have above.
Mar 10 '14 #2
Dlovan
5
try it

strSQL = "Select * from students where Level BETWEEN " _
& """" & tablename.LL & """ and """ & tablename.UL & """ and tablename.boarder = '';"
Mar 10 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sreddy | last post by:
I am trying to write a sql query on self referencing table. Just to brief ..Database is related to a Hiring department of the Qwest company. I need to generate a Report used by in HR...
2
by: Fred | last post by:
Hi. How do I import while mapping an excel table to an access table please??? I've searched around and all I can find is a software product or code that does the same thing as the access...
2
by: Paul Cook | last post by:
Hi, I have three tables: Countries: ID Country States: ID
12
by: Randy | last post by:
Hi, Trying to pass along a table row delete to the datasource, but I'm crashing. Here is the code: Private Sub btnDeleteIngr_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
4
by: Alexis | last post by:
Hello, I'm facing oracle trigger problem. Anyone can help or advise how to resolve it? Below are the explaination on my problem I've created a trigger for my program. When there is a new...
1
by: Wayne L | last post by:
I want to insert a selection into a table for the user to select which one. For instance: a table is being updated from other append queries but one field I want the user to select data that would...
3
by: blakerrr | last post by:
Hi All, I have a strange situation that I can't figure out. The task is quite simple, delete a record from a table. Here is my situation: I have a form called Order Create which cycles through...
9
by: Greg (codepug | last post by:
I have a combobox with the RowSourceType set to Table/Query and the RowSource is an SQL query that references a separate lookup table that contains the data that can be selected in the combobox....
7
by: Heri101 | last post by:
Experts, Please I need some sort of VBA code to drop selected queries (qryA,qryB,qryC) and all table links in (MS Access 2007) database. I am just a beginner, so please help me with complete...
1
by: SCDSC | last post by:
Hi, I need to delete all data in a table where the date is older than that in a temp table. Basically i have tblTrends and tbltempTrends. I only want new data in tblTrends as currently the data...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.