473,386 Members | 1,758 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,386 software developers and data experts.

delete non matching records access 2003

I created a query selecting non matching records and made it a delete query & get an error "specify the table conataing the records you want to delete". Help.

Thanks

Expand|Select|Wrap|Line Numbers
  1. DELETE Fuel_Assistance.[Account#], Incode_US_Alpha.[Account#]
  2. FROM Fuel_Assistance LEFT JOIN Incode_US_Alpha ON Fuel_Assistance.[Account#] = Incode_US_Alpha.[Account#]
  3. WHERE (((Incode_US_Alpha.[Account#]) Is Null));
Oct 20 '11 #1
4 1706
patjones
931 Expert 512MB
You don't need to put anything in the DELETE clause:

Expand|Select|Wrap|Line Numbers
  1. DELETE FROM Fuel_Assistance LEFT JOIN Incode_US_Alpha ON   
  2.             Fuel_Assistance.[Account#] = Incode_US_Alpha.[Account#]
  3. WHERE (((Incode_US_Alpha.[Account#]) Is Null)); 

BUT, this may not work. DELETE and UPDATE operations on JOINs are subject to referential integrity constraints. If the tables are designed in such a way that a DELETE operation from one side of the JOIN does not cascade to the other side of the JOIN, then the operation will fail.

You could also DELETE from the two tables separately.

Pat
Oct 20 '11 #2
Thanks for you time and advice. I chose to write a small VB function instead.

Thanks again.
Oct 21 '11 #3
patjones
931 Expert 512MB
OK. If you're able to post your solution to the thread, please do so as people might like to know how you went about this. Thanks.
Oct 21 '11 #4
This is the solution I came up with
Expand|Select|Wrap|Line Numbers
  1. Public Function Reorg_File()
  2. 'Select Inactive customers to delete
  3. Dim db As Database
  4. Dim rs1 As DAO.Recordset
  5. Dim rs2 As DAO.Recordset
  6. Dim strCriteria As String
  7.  
  8. Set db = CurrentDb
  9. DoCmd.SetWarnings False
  10. ' Created a make table query to build tbl_Assist_Delete records
  11. DoCmd.OpenQuery "qry_Assist_Delete_Table", , dbOpenDynaset
  12. Set rs1 = db.OpenRecordset("tbl_Assist_Delete", dbOpenDynaset)
  13. Set rs2 = db.OpenRecordset("tbl_Assistance", dbOpenDynaset)
  14.  
  15.   With rs1
  16.      rs1.MoveFirst
  17.       While Not rs1.EOF
  18.  
  19.      rs2.MoveFirst
  20.      strCriteria = "[Account#] = " & """" & rs1.Fields("Account#") & """"
  21.  
  22.        rs2.FindFirst strCriteria
  23.  
  24.       If rs2.NoMatch Then
  25.         MsgBox "Record not found"
  26.       End If
  27.  
  28.             rs2.Delete
  29.  
  30.             .MoveNext
  31.      Wend
  32.  
  33.    End With
  34.  
  35. rs1.Close
  36. rs2.Close
  37. End Function
Oct 21 '11 #5

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

Similar topics

2
by: laurenq uantrell | last post by:
I'm hoping someone can tell me how to construct a stored procedure that deletes all records in tblA not matching the PK in tblB This gives me the recordset of all records in tblA with no matching...
17
by: Jana | last post by:
Howdy! I have an Access 2003 SP1 where data tables reside on a server & each workstation runs the front end locally. All 5 users are on the same version of Access. We've been having problems on...
3
by: klufkee | last post by:
Hi all, I have two tables that are related to each other. One has 30K records while the other has 500. I ran a 'Without Matching' query to find records in the larger table that didn't have a...
3
by: Sheldon | last post by:
I have the following query expression - Like Format((!!)) & "/*/" & (! !) which would translate to e.g. 04/*/2007 if someone is running a report for last month. The above expression is part of a...
3
by: Kalaine | last post by:
Access 2003: The following code is intended to delete the current record and all child records but results in an error, help please, thx. Private Sub CmdDelBSR_Click() On Error GoTo...
2
by: nina | last post by:
is there a way to group records in forms in 2003 version ie. i have number of records with date and would like to see it in this way on a form sep 2007 rec1 rec2 rec4 .. ..
1
by: Bobby | last post by:
Hi I am using Access 2003 mdb as a front end to an application which uses SQL Server 2000 as the backend. The two are connected using ODBC. On one particular table (the Stock table), I have a...
3
by: marcf | last post by:
Hi Everyone, Hopefully someone will be able to offer a suggestion to this problem. I have a multi user CMS running at work which I wrote. Aside from a few bugs everything has been going fine...
5
WyvsEyeView
by: WyvsEyeView | last post by:
Upon clicking Delete to delete the current record on frmTopics, I want several things to happen: 1) Display a custom message rather than Access's standard "You are about to delete n records" one....
1
by: kilabyte | last post by:
I have a csv file that I download from a remote server every morning at 8am. This is imported in access and written to an Access table on one of the servers, having first deleted the previous days...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.