Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ARRANGE this Access coe to vb6

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
425
IT
Code:
Option Compare Database
Option Explicit

Sub RemoveDuplicates()

  Dim CN As ADODB.Connection
  Dim RST As New ADODB.Recordset
  Dim strTable As String
  
  Set CN = CurrentProject.Connection
  
  strTable = "COMUNI_GEOCODE"
  RST.Open strTable, CN, adOpenKeyset, adLockOptimistic, adCmdTableDirect
  
  Do While Not RST.EOF
    If DCount("*", strTable, "CF=" & Chr(34) & RST!CF & Chr(34)) > 1 Then
      RST.Delete
    End If
    RST.MoveNext
  Loop
  
End Sub

i have tested in vb6 ide but Dcount not exists in vb6

other way are welcome!
 
Code:
Select * From
(Select COUNT(CF) As MyCount, CF
From COMUNI_GEOCODE
Group By CF)
Where MyCount > 1

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
HI Andy, sorry me, but i need to delete records duplicate not a select.
 
The best way to avoid duplicate records - in my opinion - is to not allow them to happen in the first place. Check before INSERTing a record if such a record already exists.

But if you want to do it the other way, here is one way, and here are another 3 ways

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Were any of the links in the sample provided by Andy useful to you?

The one I've used in the past with success is pretty much [tt]Method 3[/tt] under [tt]Remove Duplicates and Keep Row With Lowest ID[/tt] from the first link. It does rather assume you have a unique ID code column
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top