Imam dve tabele u bazi podataka, u jednoj tabeli imam dosta unosa koji se nalaze i u drugoj tabeli pa bih hteo da ih obrišem.
Našao sam vb kod na netu, on mi je pomogao da obrišem duplikate u okviru jedne tabele, ne znam da programiram u vbu ali mislim da treba samo malo da se doradi ovaj kod da bih mogao da ga koristim sa dve tabele.
Zna li neko!!! Hitno mi je potrebno!!
"
Option Compare Database
Option Explicit
Sub Remove_Duplicates()
'change "**Duplicates**" to target table name (leave perins)
'change "**Duplicate_ID**" to column name containg the duplicate information
Dim str_Duplicate_column(2) As String
str_Duplicate_column(1) = "**Duplicate_ID**"
str_Duplicate_column(2) = "**Duplicate_ID**"
Call Remove_Duplicates_Leave_One("**Duplicates**", str_Duplicate_column)
End Sub
Sub Remove_Duplicates_Leave_One( _
pstr_Target_Table As String, _
pstr_Duplicate_Column() As String)
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim str_sql As String
Dim var_Current_Value(2) As Variant
Dim var_Previous_Value(2) As Variant
Set dbs = Access.CurrentDb
pstr_Target_Table = "[" & pstr_Target_Table & "]"
pstr_Duplicate_Column(1) = "[" & pstr_Duplicate_Column(1) & "]"
pstr_Duplicate_Column(2) = "[" & pstr_Duplicate_Column(2) & "]"
'Orders recordset so duplicates are sequential
str_sql = _
"SELECT " & _
pstr_Duplicate_Column(1) & "," & _
pstr_Duplicate_Column(2) & " " & _
"FROM " & _
pstr_Target_Table & " " & _
"ORDER BY " & _
pstr_Duplicate_Column(1) & "," & _
pstr_Duplicate_Column(2)
Set rst = dbs.OpenRecordset(str_sql, dbOpenDynaset)
Do While Not rst.EOF
var_Previous_Value(1) = rst(pstr_Duplicate_Column(1))
var_Previous_Value(2) = rst(pstr_Duplicate_Column(2))
rst.MoveNext
Delete_Another_Duplicate_Maybe:
If rst.EOF Then Exit Do
var_Current_Value(1) = rst(pstr_Duplicate_Column(1))
var_Current_Value(2) = rst(pstr_Duplicate_Column(2))
If _
var_Previous_Value(1) = var_Current_Value(1) _
And _
var_Previous_Value(2) = var_Current_Value(2) _
Then
rst.Delete
rst.MoveNext
If Not rst.EOF Then
var_Current_Value(1) = rst(pstr_Duplicate_Column(1))
var_Current_Value(2) = rst(pstr_Duplicate_Column(2))
'var_Previous_Value will maintain original value
GoTo Delete_Another_Duplicate_Maybe:
End If
End If
Loop
End Sub
"