ADO recordset query quandery locating duplicates

James Snyder

Well-known Member
Joined
Jan 11, 2013
Messages
618
I am having trouble setting up a query for a recordset that will list duplicates for an automated process to clean up. I am using Excel 2010 with Microsoft ActiveX Data Objects Recordset 6.0 Library and Microsoft ActiveX Data Objects 6.1 Library as references.

So far, I have chopped the query down to it's most basic elements and reassembled until it broke. Necessary pieces work well, but when I combine them, I get nowhere.

Here is the working simple query to retrieve a single row:
Code:
    dupeSQL = "SELECT PSID FROM [Obstructed$] "

Here is the working single query to retrieve a count:
Code:
     dupeSQL = "SELECT COUNT(PSID) As '" & "CountPSID" & "' " _
        & "FROM [Obstructed$] "

When combined, I cannot figure out why it won't work:
Code:
    dupeSQL = "SELECT [PSID], COUNT(PSID) As '" & "CountPSID" & "' " _
        & "FROM [Obstructed$] "

Here is what I am trying to get to:
Code:
    dupeSQL = "SELECT [PSID], COUNT(PSID) As '" & "CountPSID" & "' " _
        & "FROM [Obstructed$] " _
        & "WHERE COUNT(PSID) > 1 " _
        & "GROUP BY PSID"

I can even work without the GROUP BY. I have also played with the HAVING clause to try and accommodate the [PSID] field, but have gotten nowhere.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Although I would still be happy to learn the answer, I have abandoned ADO as a tool for this project.
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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