473,406 Members | 2,707 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,406 software developers and data experts.

Deleting a similar record

3
Hi,

I have a simple Access Table (LstFax) with "REF" (Client NAme) and "ADDR" (Fax numbers) fields that has been generated by SQL from a custom query form. There are duplicate fax numbers for clients from the same office that I want to delete.

I have a sub to try and delete these similar field based on some code I found on the net using From ... From syntax but am having some problems. I can't find syntax to suport this - maybee its just not available for access

Any help much appreciated. The "REF" field is not important. I would like to keep it in SQL without new tables / queries to save space - keep it seemles for users.

Sub RmvDupRec(TabNam As String, TabFld As String, FldUnq As String)

Dim SQLstr As String

SQLstr = "DELETE FROM " & TabNam
SQLstr = SQLstr & " FROM " & TabNam & " As T1, " & TabNam & " As T2"
SQLstr = SQLstr & " WHERE T1." & TabFld & " = T2." & TabFld
SQLstr = SQLstr & " AND T1." & FldUnq & " > T2." & FldUnq & ";"
MsgBox SQLstr

DoCmd.SetWarnings False
DoCmd.RunSQL SQLstr
DoCmd.SetWarnings True

End Sub

the SQL looks like

DELETE FROM LstFax FROM LstFax As T1, LstFax As T2 WHERE T1.ADDR = T2.ADDR AND T1.REF > T2.REF;

Thanks

KPoe
Mar 19 '08 #1
3 1392
Try the command as
DELETE FROM LstFax As T1, LstFax As T2 WHERE T1.ADDR = T2.ADDR AND T1.REF > T2.REF;
Mar 19 '08 #2
KPoe
3
thanks kavitadatar ,

No such luck. Error 3128 - specify table containing records you want to delete

I am wondering if I have to go about this a different way?

KPoe
Mar 19 '08 #3
KPoe
3
After a bit more searching, I managed to get the following solution.

First I created another table containing the duplicate fax numbers. The SQL is

SELECT DISTINCTROW LstFax.REF, LstFax.ADDR INTO LstTmp FROM LstFax LEFT JOIN LstFax AS LstFax_1 ON LstFax.ADDR = LstFax_1.ADDR WHERE (((LstFax.ADDR) In (SELECT [ADDR] FROM [LstFax] As Tmp GROUP BY [ADDR] HAVING Count(*)>1 )) AND ((LstFax.REF)>[LstFax_1].[REF]));

I then used this table to delete duplicate records in the origional table.

DELETE DISTINCTROW LstFax.* FROM LstFax RIGHT JOIN LstTmp ON LstFax.REF = LstTmp.REF;

Hope this helps someone

KPoe
Mar 26 '08 #4

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

Similar topics

0
by: Andre Doreid Berro | last post by:
Greetings All I am working on an Access database of contacts. I have plenty of records but plenty of them are almost duplicates. Data in some fields are misspelled and entered as completly...
1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
3
by: vishnu mahendra | last post by:
hello to all, Can any one please tell me how to delete a record in a binary file. thank you in advance, vishnu
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
19
by: MaXX | last post by:
Hi, I hope I'm not OT. I have the following issue: I want to delete a record from my db with a php script. Let's say I'm auth'd and I want to delete the record id 440. With a simple form (get...
2
by: Armando | last post by:
I created a report to display all the tables/fields in a db, and all the code is in the report's module - for easy one-chunk portability to other apps. In the OnOpen, I create a temp table, fill...
4
by: sphinney | last post by:
I'm not exactly sure how to start this post. My question is pretty simple, but it will take a little bit of context before I can state it. (And thanks in advance for taking the time to read this!) ...
1
by: Kyosuke18 | last post by:
Hi everyone, I have a problem in deleting a data that is connected on the database.. I tried this code but it shows me an error: Run-time error '-2147217900(80040e14)': Syntax error in string in...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.