I'm not sure that this whole process makes sense to me, so hopefully this is
of some use.
We will assume that the source table has:
a) a primary key field named ID. (Otherwise the seek on rs2 will find the
*same* record as the one in rs1.)
b) a yes/no field named IsDead, which we will set to Yes to indicate the
record is to be deleted. (This lets you track what's happening, and verify
it all works before any deletion takes place.)
Function CheckBlanks(strField as String, strAlphaOrNumeric As String) As
Long
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim rs3 As DAO.Recordset
Dim strSql As String
Dim strWhere As String
Dim strDelim As String
If strAlphaOrNumeric <> "Numeric" Then
strDelim = """"
End If
Set db = dbEngine(0)(0)
strSql = "SELECT " & strField & ", IsDead FROM [01 - Input Data] ORDER
BY ID;"
Set rs1 = db.OpenRecordset(strSql)
Set rs2 = db.OpenRecordset(strSql)
Set rs3 = db.OpenRecordset("Removed Transactions", dbOpenDynaset)
Do While Not rs1.EOF
If Not IsNull(rs1(strField)) Then
strWhere = "(" & strField = " & strDelim & rs1(strField) &
strDelim & ") AND (ID <> " & rs1!ID & ")"
'Debug.Print strWhere
rs2.FindFirst strWhere
If rs2.NoMatch Then
rs3.AddNew
rs3(strField) = rs1(strField)
rs3.Update
rs2.Edit
rs2!IsDead = True
rs2.Update
End If
rs1.MoveNext
Loop
rs3.close
rs2.close
rs1.close
set rs3 = nothing
set rs2 = nothing
set rs1 = nothing
strSql = "DELETE FROM [01 - Input Data] WHERE IsDead = True;"
db.Execute strSql, dbFailOnError
'Return the number of record deleted.
CheckBlanks = db.RecordsAffected
set db = nothing
End Function
You will need to do your own debugging from there, Tom. (Again, the approach
seems like a lot of unnecessary work to me.)