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

Delete Duplicated Rows

ahmedtharwat19
hi, every one

for delete duplicated rows can any one up to us an example to see that

because i`m beginning to ms access

and i have a problem about that

thank you for all
abo mroan
Nov 15 '09 #1
12 2861
NeoPa
32,556 Expert Mod 16PB
When posting your question it is necessary to put it in its own thread. Hijacking somebody else's (Delete Duplicate records) is not acceptable. It is acceptable to post a link if you think it's relevant though. I have split it away for you (and included a link across), but please remember in future.
Nov 15 '09 #2
NeoPa
32,556 Expert Mod 16PB
If you had read the previous thread you would have seen that posts #9 & #10 have examples of code for this job. Unfortunately, as you haven't explained what you need other than very generally, I cannot say how well suited either is for your needs. In case it helps though (and for anyone finding this in a search) I will include my code from Post #10 of Delete Duplicate records.

This code assumes a table in the local db but it can be tweaked or enhanced.
For instance, if the one to be kept must have the lowest Primary Key value then it could be changed to do that.
Expand|Select|Wrap|Line Numbers
  1. 'DelDups Removes duplicate records in strTable matched on strField
  2. Public Sub DelDups(strTable As String, strField As String)
  3.     Dim strSQL As String, varLastVal As Variant
  4.  
  5.     'Recordset must be full table but sorted by the field we're checking
  6.     strSQL = "SELECT * FROM [" & strTable & "] ORDER BY [" & strField & "]"
  7.     With CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
  8.         varLastVal = Null
  9.         'For each record, check against previous value in strField
  10.         'If same then this is a duplicate so can be removed
  11.         Do Until .EOF
  12.             If .Fields(strField) = varLastVal Then
  13.                 Call .Delete
  14.             Else
  15.                 varLastVal = .Fields(strField)
  16.             End If
  17.             Call .MoveNext
  18.         Loop
  19.     'Ending the 'With' releases the Recordset
  20.     End With
  21. End Sub
Hope it helps.
Nov 15 '09 #3
Mr NeoPa

it`s a perfect code thank you very much

but what the condition if there 2 fields

i try it and it work as well

Expand|Select|Wrap|Line Numbers
  1. 'DelDups Removes duplicate records in strTable matched on strField
  2. Public Function DelDups(strTable As String, strField As String, strField1 As String)
  3.     Dim strSQL As String, varLastVal As Variant, varLastVal1 As Variant
  4.  
  5.     'Recordset must be full table but sorted by the field we're checking
  6.     strSQL = "SELECT * FROM [" & strTable & "] ORDER BY [" & strField & "] , [" & strField1 & "]"
  7.     With CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
  8.         varLastVal = Null
  9.         varLastVal1 = Null
  10.  
  11.         'For each record, check against previous value in strField
  12.         'If same then this is a duplicate so can be removed
  13.         Do Until .EOF
  14.             If .Fields(strField) = varLastVal And .Fields(strField1) = varLastVal1 Then
  15.                 Call .Delete
  16.             Else
  17.                 varLastVal = .Fields(strField)
  18.                 varLastVal1 = .Fields(strField1)
  19.  
  20.             End If
  21.             Call .MoveNext
  22.         Loop
  23.     'Ending the 'With' releases the Recordset
  24.     End With
  25. End Function
thank you
Jun 6 '10 #4
missinglinq
3,532 Expert 2GB
When posting your question it is necessary to put it in its own thread. Hijacking somebody else's (Delete Duplicate records) is not acceptable.
Careful, NeoPa! You appear to be discipling someone in public!

Linq ;0)>
Jun 6 '10 #5
NeoPa
32,556 Expert Mod 16PB
Ah well Linq my friend. I'm still sane aren't I.
Jun 6 '10 #6
NeoPa
32,556 Expert Mod 16PB
ahmedtharwat19: but what the condition if there 2 fields

i try it and it work as well
Indeed. It seems you have understood the concept well enough to modify it for slightly changed circumstances.

Well done :)
Jun 6 '10 #7
@NeoPa
yes, thank you for all.
Jun 7 '10 #8
missinglinq
3,532 Expert 2GB
@NeoPa
I'm sure you are, Ade, but apparently some are not!

Linq ;0)>
Jun 7 '10 #9
@NeoPa
i`m sorry idont understand what do you mean , i just add this for that thread to complete the thread in same problem.

Generally, thank you for an advice.

Best Regards ,
Medo
Jun 7 '10 #10
NeoPa
32,556 Expert Mod 16PB
missinglinq: I'm sure you are, Ade, but apparently some are not!
I'd hate to be confused with someone who thought that way ;)
Jun 8 '10 #11
NeoPa
32,556 Expert Mod 16PB
ahmedtharwat19: i`m sorry idont understand what do you mean , i just add this for that thread to complete the thread in same problem.
I'm happy to explain :)

Generally, a thread is focused around the problem of the Original Poster (or OP). Answers of many varieties are encouraged. Further questions that are likely to take the focus away from the OP's requirements are considered unwelcome (they are against the rules in fact). In this case, your post was directing the thread away from the OP's question and onto your requirements. That is a hijack.

That said, we don't wish you to go unsupported, we simply want to keep the structure clean. You can post your question in it's own thread (as we now have) and all should be well.

I hope that makes it clearer for you.
Jun 8 '10 #12
thank you,

i`m sorry my english is not good. i think it very bad.

but i have a problem in this site because i add the thread

title:create a module via vba in current database or in another database

but kub365 was delete it , he think it`s a Homework/Coursework.

I`m an Accountant From 2001, and the vba(ms access) is just my hoppy.

please help me !!??..

(medo)
Jun 8 '10 #13

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

Similar topics

3
by: Mirek Rusin | last post by:
....what is the best way to force duplicated unique or primary key'ed row inserts not to raise errors? duplicated rows can be ignored or updated as well - it really doesn't matter. to be...
1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
1
by: Patrizio | last post by:
Hi All, I've the following table with a PK defined on an IDENTITY column (INSERT_SEQ): CREATE TABLE MYDATA ( MID NUMERIC(19,0) NOT NULL, MYVALUE FLOAT NOT NULL, TIMEKEY ...
0
by: GlobalBruce | last post by:
The GAC on my development computer has several assemblies which are duplicated. For instance, the System assembly is present as two different native images as well as the non-native version. The...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
6
by: Ryan Liu | last post by:
Hi, If I have tens of thousands DataRow in a DataTable and allow the end user to pick any DataColumn(s) to check for duplicated lines, the data is so large, is there a better API, algorithm can...
2
by: Radu | last post by:
Hi. I have a "union" table which results of a union of two tables. Occasionally I could have duplicates, when the same PIN has been added to both tables, albeit at different Datees/Times, such...
3
by: Michel Esber | last post by:
Hello, Environment: DB2 LUW v8 FP15 / Linux I have a table with 50+ Million rows. The table structure is basically (ID - Timestamp). I have two main applications - one inserting rows, and the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.