Ms-access – How to set up data entry in many-to-many database in Access 2010 with forms/subforms

database-designms access

I have a simple two table database in Access 2010 tracking landowners and properties. They are related in a many-to-many (M:M) relationship with a link table. Forms for viewing data have been generated from two queries following tutorial here. There are two forms with subforms:
'landowners and their associated properties'
and 'properties and associated landowners'.

I would like the option for users to either (1) add a new record to the subform (creating a relationship record in the link table and a new record in the source table for the subform) or (2) select from a list of existing records to relate to the property / landowner.

So far, I have (1) working. In the subform, if a new record is inserted it populates the appropriate table and creates a relationship. If the record is deleted from the subform, the relationship is deleted from the link table but the record is NOT deleted in the subform's source table (child table) — as desired.

I have attempted a drop-down combobox providing the option to select from existing records in the subform's source table but I get a duplicate error. Any help?

Best Answer

The general idea is that you create a subform that's bound to your link table, and make one of the fields in the subform a combo box bound to the child record ID that's in your link table. Fill the combo box using records in the child table.

Then you handle the NotInList event on the combo box to prompt the user to add the record to the child table (or whatever is appropriate for your application).

NotInList Event

Then if you want to actually remove rows from the child table when they are no longer referenced by the link table, handle the appropriate deletion event on your subform, and check for unreferenced records.

I've implemented something like this once, but I think it was in Access 2000 on a machine I don't have with me at the moment. I'll try to check it later out of curiosity.