DUPLICATE

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

DUPLICATE

Post by sal21 »

OLD post...

Code: Select all

 
 Option Compare Database
Option Explicit
Sub RemoveDuplicates()
    
    Dim cnn As ADODB.Connection
    
    Dim rst As New ADODB.Recordset
    
    Dim strTable As String, Y As Long, I As Long
    
    ' Set the connection here
    
    Set cnn = CurrentProject.Connection
    
    ' Substitute the name of the table here
    
    strTable = "DATI"
    
    rst.Open strTable, cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
    
    Do While Not rst.EOF
        
        DoEvents
        
        'NUMERO
        
        'If DCount("*", strTable, "RAPPORTO=" & rst!RAPPORTO) > 1 Then
        
        'TEST0
        
        If DCount("*", strTable, "NRISCR=" & Chr(34) & rst!NRISCR & Chr(34)) > 1 Then
            
            rst.Delete
            
            I = I + 1
            
        End If
        
        rst.MoveNext
        
        Y = Y + 1
        
    Loop
    
End Sub
 
i need to add a new key COLLEGIO with NRISCR...
How to?

User avatar
HansV
Administrator
Posts: 78378
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DUPLICATE

Post by HansV »

Please explain in more detail
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

Re: DUPLICATE

Post by sal21 »

HansV wrote:
24 Jan 2022, 13:13
Please explain in more detail
I need a to find duplicates with a join on two fields...

COLLEGIO&NRISCR

User avatar
HansV
Administrator
Posts: 78378
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DUPLICATE

Post by HansV »

If DCount("*", strTable, "NRISCR=" & Chr(34) & rst!NRISCR & Chr(34) & " AND COLLEGIO=" & Chr(34) & rst!COLLEGIO & Chr(34)) > 1 Then
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

Re: DUPLICATE

Post by sal21 »

HansV wrote:
24 Jan 2022, 14:47
If DCount("*", strTable, "NRISCR=" & Chr(34) & rst!NRISCR & Chr(34) & " AND COLLEGIO=" & Chr(34) & rst!COLLEGIO & Chr(34)) > 1 Then
:cheers:

But instead to set direclly the table i can use a sql query to set the recordsets for analisys?

and

i can use in vb6 ADO, connection?

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

Re: DUPLICATE

Post by sal21 »

HansV wrote:
24 Jan 2022, 14:47
If DCount("*", strTable, "NRISCR=" & Chr(34) & rst!NRISCR & Chr(34) & " AND COLLEGIO=" & Chr(34) & rst!COLLEGIO & Chr(34)) > 1 Then

Sorry bro...
now i have this my query, but dont work!

If DCount("*", strTable, "GIORNO=" & Chr(34) & rst!GIORNO & Chr(34) & " AND FILA=" & Chr(34) & rst!FILA & Chr(34) & " AND NUMERO=" & Chr(34) & rst!NUMERO & Chr(34)) > 1 Then

the field GIORNO have a date property

the fields, FILA and NUMERO have a numeric property

User avatar
HansV
Administrator
Posts: 78378
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DUPLICATE

Post by HansV »

Chr(34) = ". This is used for text values.
For date values, use # and USA date format.
For numeric values, no special character is needed.


If DCount("*", strTable, "GIORNO#=" & Format(rst!GIORNO, "mm/dd/yyyy") & "# AND FILA=" & rst!FILA & " AND NUMERO=" & rst!NUMERO) > 1 Then
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

Re: DUPLICATE

Post by sal21 »

:cheers: :clapping:
HansV wrote:
22 Feb 2022, 17:09
Chr(34) = ". This is used for text values.
For date values, use # and USA date format.
For numeric values, no special character is needed.


If DCount("*", strTable, "GIORNO#=" & Format(rst!GIORNO, "mm/dd/yyyy") & "# AND FILA=" & rst!FILA & " AND NUMERO=" & rst!NUMERO) > 1 Then
But i can run/call the module via vb6? or i can have the same result with via SQL in vb6?

User avatar
sal21
PlatinumLounger
Posts: 4339
Joined: 26 Apr 2010, 17:36

Re: DUPLICATE

Post by sal21 »

HansV wrote:
22 Feb 2022, 17:09
Chr(34) = ". This is used for text values.
For date values, use # and USA date format.
For numeric values, no special character is needed.


If DCount("*", strTable, "GIORNO#=" & Format(rst!GIORNO, "mm/dd/yyyy") & "# AND FILA=" & rst!FILA & " AND NUMERO=" & rst!NUMERO) > 1 Then

User avatar
HansV
Administrator
Posts: 78378
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DUPLICATE

Post by HansV »

DCount is available in VBA in Access, not in VB6. You could open a recordset on the SQL string

SQL = "SELECT * FROM [" & strTable "] WHERE GIORNO#=" & Format(rst!GIORNO, "mm/dd/yyyy") & "# AND FILA=" & rst!FILA & " AND NUMERO=" & rst!NUMERO

Use the MoveLast method of the recordset, then get its RecordCount.
Best wishes,
Hans