I am trying to delete all multiple records in ARPs and I can#t figure out why this doesn't work. I get an Error 3075 when I run this in ACCESS saying:
"Syntax Error in Date in Query 'ARPs.ARPNR = 'CLU7BG' AND ARPs.Änderungsdatum < #29.07.2016 12:21:42'"
Thanks for any help you can provide.
Dim strSQL As String
Dim allMult As DAO.Recordset
strSQL = "SELECT ARPs.ARPNR, ARPs.Änderungsdatum FROM ARPs WHERE ARPs.BTNR IN (SELECT BTNR FROM ARPs GROUP BY BTNR HAVING COUNT(*) > 1);"
Set allMult = CurrentDb.OpenRecordset(strSQL)
With allMult
'Check that the Recordset isn't empty
If Not .BOF And Not .EOF Then
.MoveLast
.MoveFirst
'Loop until we reach the end of the Recordset
While (Not allMult.EOF)
'Delete all except the newest multiple records
strSQL = "DELETE * FROM ARPs WHERE ARPs.ARPNR = '" & allMult.Fields("ARPNR") & "' AND ARPs.Änderungsdatum < #" & allMult.Fields("Änderungsdatum") & "# ;"
CurrentDb.Execute strSQL, dbFailOnError
.MoveNext
Wend
End If
'close the Recordset
.Close
End With
'release memory
Set allMult = Nothing