How to delete the duplicates rows in a single MS Access column?
I'v got the code for Excel's VBA:
I guess "set rowcount" is not supported by MS Access.
I've asked this before at Stackoverflow, but there is still no solution.
I'v got the code for Excel's VBA:
Code:
Sub AccessDB()
Dim db_file As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
db_file = "c:\Files\"
db_file = db_file & "accdb.mdb"
Set cn = New ADODB.Connection
cn.ConnectionString = _
"Provider=Microsoft.Ace.OLEDB.12.0;" & _
"Data Source=" & db_file & ";" & _
"Persist Security Info=False"
cn.Open
'duplicates delete----------------------------------
Set rs = cn.Execute("SELECT Base, count(*)" & _
"FROM AccessBase GROUP BY Base HAVING count(*) > 1")
cn.Execute ("set rowcount 1;" &_
"delete from AccessBase where Base = rs.Fields(0)")
'-----------------------------------------------------
cn.Close
End Sub
I guess "set rowcount" is not supported by MS Access.
I've asked this before at Stackoverflow, but there is still no solution.
Last edited: