populate a many-to-many table with access

大兔子大兔子 提交于 2019-12-04 14:10:39

You should not need persons, only persons_projects. I assume that persons_projects consists of:

person_id  -> FK  ) Combined as PK, perhaps, if not, an autonumber PK
project_id -> FK  )

and (recommended) a datetime stamp and user field.

The subform is set-up with a Link Child and Master Field of project_id, which will be automatically completed by Access, and a combobox similar to:

Control Source: person_id
Row Source: SELECT person_id, surname & " " & forename, some_field FROM persons
Bound Column: 1
Column Count: 3 
Column Widths: 0cm;2cm;2cm 

Edit re Comments

It is possible, though often a little more difficult, to include both tables and have an updatable recordset, the query (view) should include both project_id and person_id from the junction table.

Sounds like persons is the driving dataset here since you want to be able to link it to multiple projects as well as delete the person record.

Base your form on the Persons table. A subform should be based on the person_projects table and linked by the corresponding id's. You can use a combo box on the projectid in the subform and have some other field displayed so the user can identify the project (name?). You may want to show all the project data for each project on this form, but you may find it getting very confusing to the user. Having a separate form that you can 'pop-up' to give more project information may be a better choice.

If you want to delete a person, you can just delete from the persons table, but you need to decide if you want any orphan records in the person_projects table (Which you shouldn't). It's easy in Access to establish a link with referencial integrity (cascading update and delete optional). It's up to you as to how robust this needs to be.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!