This is how I set it up.
1) the user inputs a part on the part form.
2) the user click a command button to assign categories and classes. I am going to assign all the categories and then later delete any not given a class
3) Run the update query and open the form
Code:
Private Sub Command4_Click()
' Add all categories
DoCmd.SetWarnings (False)
DoCmd.OpenQuery "qryAddCategories"
DoCmd.SetWarnings (True)
'open form to specified part
DoCmd.OpenForm "frmPartCatClass", , , "PartID = " & Me.PartID
End Sub
in the above code "qryAddCategories" is an append qry that assigns all the categories to tblPartCat for the given part on the form. If the part cat combination is already in the table it is not duplicated. This is the complicated part and may give you trouble if all our names are not Identical. (Note access for some reason does not like this query. I can run it and get the correct results, but after saving it I can not open it up in design view)
Code:
qryAddCategories
INSERT INTO tblPartCat ( catID, PartID )
SELECT tblCategory.catID, [Forms]![frmPartsInformation]![PartID] AS PartID
FROM tblCategory LEFT JOIN tblPartCat ON (tblCategory.catID = tblPartCat.catID) AND ( tblPartCat.PartID = [Forms]![frmPartsInformation]![PartID])
WHERE (((tblPartCat.PartID) Is Null));
So basically if you started with Part 1 on your main form you would create in tblPartCat something like
Part ID catID classID
1 1 null
1 2 null
1 3 null
1 4 null
to
1 60 null
Now my continous form frmPartCatClass opens to all records for Part ID one. Here is the forms query:
Code:
SELECT tblParts.PartName, tblPartCat.PartID, tblPartCat.catID, tblCategory.catName, tblPartCat.classID
FROM ((tblParts RIGHT JOIN tblPartCat ON tblParts.PartID = tblPartCat.PartID) LEFT JOIN tblClass ON tblPartCat.classID = tblClass.classID) LEFT JOIN tblCategory ON tblPartCat.catID = tblCategory.catID
ORDER BY tblCategory.catName;
on the form I show Part name (locked), catName (locked) and my option group bound to (tblPartCat.classID).
I think this looks like what you are describing.
4) The user then assigns classes to every part's category.
5) When he is done he closes the form and anything not assigned a class is deleted
Code:
Private Sub Form_Close()
DoCmd.SetWarnings (False)
DoCmd.OpenQuery "qryDeleteNoClass"
DoCmd.SetWarnings (True)
End Sub
6) the delete query looks like this
Code:
DELETE tblPartCat.classID
FROM tblPartCat
WHERE (((tblPartCat.classID) Is Null));
I think this is a common dilemma. Bound controls are easy to show what records are present, but it often takes a little code to show what records are not selected or remaining.