I have a problem I need to create vba code for ms access 2016 which will copy the contents of table 1 to table 2 with
If there are duplicates in Table 2, it displays a message about the duplicates and a question whether to continue or abort.
I have this vba code but I don't know how to convert it to work the way I want I got this error on image
Private Sub txtVWI_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_txtVWI_BeforeUpdate
Dim intResponse As Integer
Dim strTable As String
Dim strFind As String
Dim strSQL As String
Dim rst As ADODB.Recordset
Dim Conn As ADODB.Connection
Set Conn = CurrentProject.Connection
Set rst = New ADODB.Recordset
strTable = "Główna"
strSQL = "SELECT Count(Główna.Data/Godzina) AS Duplikaty" & _ " FROM Główna" & _ " GROUP BY Główna.Data/Godzina" & _ " HAVING Count(Główna.Data/Godzina)>1"
Set rs = db.OpenRecordset(strSQL)
If rs.RecordCount = 0 Then strSQL = "INSERT INTO Główna" & _ " SELECT Tymczasowa.*" & _ " FROM Tymczasowa" DoCmd.RunSQL (strSQL)
rst.Open strSQL, Conn
If rst(0) > 0 Then ' duplikaty znalezione.
If Me.NewRecord Then
intResponse = MsgBox("Ten zestaw danych już istnieje" & vbCrLf & "chcesz zduplikować zestaw danych?", vbYesNo)
If intResponse = vbNo Then
Me.Undo
End If
End If
End If
Exit_txtVWI_BeforeUpdate:
Exit Sub
rst.Close
Conn.Close
Set rst = Nothing
Set Conn = Nothing
Err_txtVWI_BeforeUpdate:
MsgBox Err.Description
Resume Exit_txtVWI_BeforeUpdate
End Sub