I'll give one more attempt.
Hendrick,
To add the extra field with the group values in the tblSynonymsADD, paste this code in a code module of your example and run it.
You can run it directly from the menu "Run" of VBE or pushing F5.
Code:
Sub FillNewGroups()
Const strFromTable As String = "tblSynonymsADD"
Const strToTable As String = "tblSynonyms"
Dim db As dao.Database
Dim rsNew As dao.Recordset
Dim i As Long
On Error Resume Next
Set db = CurrentDb
'Append the NewGroup field if not exists.
db.Execute "ALTER TABLE " & strFromTable & " ADD COLUMN NewGroup Long", dbFailOnError
On Error GoTo ErrH
Set rsNew = db.OpenRecordset(strFromTable, dbOpenDynaset)
'Retrieve the max GroupFK.
i = Nz(DMax("GroupFK", strToTable), 0)
MsgBox "New groups starts from " & i + 1, vbInformation, "Fill new groups"
'Fill in the NewGroup.
With rsNew
While Not .EOF
i = i + 1
.Edit
!NewGroup = i
.Update
.MoveNext
Wend
MsgBox .RecordCount & " groups filled in succesfully up to " & i, vbInformation, "Fill groups"
End With
ExitHere:
On Error Resume Next
rsNew.Close
Set rsNew = Nothing
Set db = Nothing
Exit Sub
ErrH:
MsgBox Err.Description, vbExclamation, "Fill new groups (Error: " & Err & ")"
Resume ExitHere
End Sub
Now, the query below returns the new words in one single field and the corresponding new group values:
Code:
SELECT Field1 AS NewWord, NewGroup FROM tblSynonymsADD
UNION ALL
SELECT Field2 AS NewWord, NewGroup FROM tblSynonymsADD;
The query below restricts the new words that exists in the tblSynonyms:
Code:
SELECT n.NewWord, n.NewGroup FROM
(SELECT Field1 AS NewWord, NewGroup FROM tblSynonymsADD
UNION ALL
SELECT Field2 AS NewWord, NewGroup FROM tblSynonymsADD) AS n
LEFT JOIN tblSynonyms ON n.NewWord = tblSynonyms.TheWord
WHERE (((tblSynonyms.TheWord) Is Null));
Finally, the query below appends the above records in the tblSynonyms:
Code:
INSERT INTO tblSynonyms ( TheWord, GroupFK )
SELECT nw.NewWord, nw.NewGroup
FROM (SELECT n.NewWord, n.NewGroup FROM
(SELECT Field1 AS NewWord, NewGroup FROM tblSynonymsADD
UNION ALL
SELECT Field2 AS NewWord, NewGroup FROM tblSynonymsADD) AS n
LEFT JOIN tblSynonyms ON n.NewWord=tblSynonyms.TheWord
WHERE tblSynonyms.TheWord Is Null) AS nw;
I hope helps.
Good Luck!
P.S.: The above steps are executed by AppendWords() procedure of my previous post.