How can I write the code?
At first,
Create a query to get the "empty Groups" :
Code:
SELECT GroupName AS EmptyGroup
FROM TableGroup
GROUP BY GroupName
HAVING Sum([Administrator])=0;
Create the append query:
(replace the red [...] with the rest field(s))
Code:
INSERT INTO TableGroupDeleted ( GroupName, UserID, [...] )
SELECT GroupName, UserID, [...]
FROM TableGroup
WHERE (((GroupName) In (SELECT EmptyGroup FROM qryEmptyGroups)));
Create the delete query:
Code:
DELETE *
FROM TableGroup
WHERE (((GroupName) In (SELECT EmptyGroup FROM qryEmptyGroups)));
Then, you can write code like that:
Code:
Dim dbs As DAO.Database
Set dbs = CurrentDb
dbs.Execute "AppendQuery", dbFailOnError
If dbs.RecordsAffected Then
dbs.Execute "DeleteQuery", dbFailOnError
Debug.Print "Deleted " & dbs.RecordsAffected & " records"
End If
'[...]
Set dbs = Nothing
Take care for error handling.
I hope helps.
Cheers,
John