Remove duplicate records in Access with VBA

JoeS01

Well-known Member
Joined
Jun 25, 2005
Messages
832
I am trying to delete the duplicate records in an Access database.
In the code below, all the records, including duplicates, are inserted in the new tblmyTemp table.

Can anyone please advise where I am going wrong, as I thought DISTINCTROW was intended to remove duplicates.

Any suggestions on how I can get a table without duplicate records?

All help and suggestions very gratefully received.

Code:
Sub Del_Dupes()

' delete duplicate records in a database table

Dim db As DAO.Database, rst As DAO.Recordset
Dim sSQL$

Set db = CurrentDb()
Set rst = db.OpenRecordset("tblTransformer")

sSQL = "SELECT DISTINCTROW INTO tblMyTemp FROM tblTransformer"

DoCmd.SetWarnings False
DoCmd.RunSQL sSQL
DoCmd.SetWarnings True

MsgBox "A table WITHOUT DUPLICATES has been created as tblMyTemp", _
  vbOKOnly, "Created"

Set rst = Nothing
Set db = Nothing

End Sub
 
Cheap and nasty method;

Build a query. Add every field to the grid EXCEPT the memos -- they shouldn't be used for searching / grouping.
Turn the query into a Totals query by pressing the big Sigma button.
Hold your breath, then run the query. With large datasets and no indexing it could take a while.

Beforehand, try running a Compact & Repair to reduce the szie of the database. It could help with the speed and make you less likely to hit the 2GB limit.

Denis
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Maybe not all 50 are needed but I would still want to understand why I can't use the code above.

It seems like it's a size problem... I can a warning message saying "either the size is greater than 2GB or"

I don't really have keys.

You are not using any of the fundamentals of RDBMS. You are really working against some of these, and making things harder for yourself than necessary.
Read this -
http://forums.aspfree.com/attachment.php?attachmentid=4712

Good luck.
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top