Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Deleting Duplicates
Dan Jackson 
            
4 years ago
Hi Guys.

I have a spreadsheet which i've simplified/normalized (Followed Multi-Table Update , Normalizing Data and Append Query) and imported into Access. I now just need to *remove* duplicates.

The dupes are identified by 2 fields, when [Client] and [Gross] are the same.
How do i delete all occurrences *Except One* for each of these?

============================================================================

I'm trying to do almost exactly what Rick is doing in the Ext cut of Normalizing Data (First Part) but with one caveat - I don't want to split the tables (Customer/orders).

To be clear, my imported table has 2500+ records and i've ran the update query which has moved all the unique values from the imported tables to the new table (Now 1013 Records so great). My problem is now how i get the rest of the info over from the imported table to the customer table

Ricks various Prevent Duplicates / Highlight Duplicates show ways of preventing and seeing duplicates but can't find anything about cleaning them. The Normalizing Data shows how to remove dupes using the index field but won't work when checking multiple fields for duplicates. Cheers



Dan Jackson OP  @Reply  
            
4 years ago
Anyone?
Alex Hedley  @Reply  
           
4 years ago
Does it matter which one you keep?
Alex Hedley  @Reply  
           
4 years ago
Untested but could get the max of each group
Store those IDs, then create another query excluding them and DELETE what is left:

SELECT id, customer, MAX(total) FROM  purchases GROUP BY id, customer
ORDER BY total DESC;
Dan Jackson OP  @Reply  
            
4 years ago
Thanks Alex. Doesn't Matter Which one is kept, as long as 1 instance remains like the 2nd pic
("A Potiwal" isn't actually a duplicate because the gross is different).

Tried your method supplementing "customer" with ClientName and "total" with ClientID

SELECT OrderT.id, OrderT.clientname, Max(OrderT.ClientID) AS MaxOfClientID
FROM OrderT
GROUP BY OrderT.id, OrderT.clientname;


Not sure where to go from here

Dan Jackson OP  @Reply  
            
4 years ago
Ah nuts. I thought i was on to something good - tried using Ricks idea of importing and setting "ClientID" as Indexed No Duplicates but instead of allowing 1 instance of each and failing the rest, it just outright refused :(

Good news is i found an alternative - using Excels remove duplicates function. I just need to use access to create the "ClientID" in the first place.

I would love to see a way of being able to do this in access. A simple, remove duplicates process without the normalization and table splitting in the Normalizing Data which made it difficult to follow.

Thanks anyway mate
Alex Hedley  @Reply  
           
4 years ago
Depends if you mind doing it in stages.
You could use that as a SubQuery to then filter out the original.
Or a MAKE TABLE with just the ID column then use that to filter out to the ones you want to delete.
Dan Jackson OP  @Reply  
            
4 years ago
I'm walking away from it for now. I've gone down the rabbit hole and come out in China! Now that i know how to do part B, i've forgotten how to do part A. I swear there is something wrong with my brain! Frustrating.

I'll come back to it next week and start from fresh
Alex Hedley  @Reply  
           
4 years ago
Just as a side note the MAX would usually be something that is different, so ClientID being the same wouldn't work.
Kevin Robertson  @Reply  
           
4 years ago
Dan,

If you wanted to go down the programming route you could delete all duplicates with a Recordset loop.
In my simple example (see screenshot) I only did 2 fields but should be easily modified for your needs.
Kevin Robertson  @Reply  
           
4 years ago

Dan Jackson OP  @Reply  
            
4 years ago
Alex Cheers, makes sense

Kevin - That looks exactly what i'm looking for, though i'm only up to expert 7 so haven't done anything with recordsets yet, though i do know the principal due to other videos. This will be a good idea for a tool i can keep in case i get any more de-dupeing to do.

Thanks guys
Richard Rost  @Reply  
          
4 years ago
Setup a 2nd table and create a composite key on those two fields. Append query your records into the new table. Voila. No programming required.
Kevin Robertson  @Reply  
           
4 years ago
I always overlook the simple solutions.
Richard Rost  @Reply  
          
4 years ago
I usually do too. My first thought is always a programming solution as well. I instantly thought recordset too. One thing that making the TechHelp videos has helped me with is to take a moment to think if there's an easier, basic solution first.
Dan Jackson OP  @Reply  
            
4 years ago
Me Likey! Thanks Rick
Dan Jackson OP  @Reply  
            
4 years ago
Its great to have the different options. I'm not afraid of the programming, Any opportunity is an opportunity to learn - i like kevins method for creating a long term tool for the future but ricks is great for getting the job done simply. Again, great opportunity to learn, so thank you
Dan Jackson OP  @Reply  
            
4 years ago
Kevin, been playing with your suggestion. Came across a few errors i had to work around including one where i was referencing ClientName in the delete instead of ID. Glad to say i got it working though!

2 Things......

- How did get the count column on your form without a query? Did you just Use DCount in a text box control source?

- I'd like to set up a similar thing for future spreadsheets so i'm thinking
     - Normalize in Excel as normal
     - Import Into Access
     - Use a config form to specify table name and maybe a list box to select which fields to check for dupes.
It's a little beyond my abilities yet since I know little about variables and recordsets. I'm guessing the selections on the "Config" form will have to be stored as a variable then fed into the De-Duping button. Exciting, if a little scary as well. I'm going to carry on my the course for now but really appreciate all you've done mate.

I'll check out Composite Key in a bit. Rick, can this be added to the video list?
Edit: To elaborate, add Composite Key to the shortcut menu drop down yo
Kevin Robertson  @Reply  
           
4 years ago
You are correct. DCount in Control Source.
Dan Jackson OP  @Reply  
            
4 years ago
Just got a situation now where i'm going to compare two spreadsheets. I'm going to load them into one table but the DCOUNT will be helpful. How do I count the dupes like you did? Thanks
Kevin Robertson  @Reply  
           
4 years ago

Dan Jackson OP  @Reply  
            
4 years ago
Thanks mate
Dan Jackson OP  @Reply  
            
4 years ago
Almost got it but i'm up against these dreaded double double quotes again. This time i'm trying to put the count in a query rather than control source. I'm also removed the Gross field, just want a count of how many duplicate "ClientNames" there are. I've watched Double Double Quotes and believe this is right but i'm getting a #error





Kevin Robertson  @Reply  
           
4 years ago
Remember you need quotes around a string.

"ClientName=""" & [ClientName] & """"

Double Double Quotes
Dan Jackson OP  @Reply  
            
4 years ago
Thanks Kevin. Must have seen that video many times and i get the premise.

In your example, you have (Minus Other bits)
"ClientName=""" & [ClientName] & """ AND Gross=" & [Gross]

So...

"ClientName"
"" & [ClientName] & ""
"


I tried this as "ClientName=""" & [ClientName] & """ as well. No Luck

Dan Jackson OP  @Reply  
            
4 years ago
No Way! Just missing the one set of quotes? Man i'm getting there but this is definitely my achillies heal!

I think i'm 90% there but can only hope that practice in the course will get me more familiar with it all
Kevin Robertson  @Reply  
           
4 years ago
Yeah, it took me a while too. In fact I still often make mistakes as well. Half the fun is figuring out what went wrong and fixing it.
Dan Jackson OP  @Reply  
            
4 years ago
hmm... I suppose "fun" is an alternative way to call it!

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 1:54:46 PM. PLT: 0s