views:

341

answers:

2

I have two tables (persons and projects) which are in a many-to-many table, thus linked together by a third table persons_projects

In ms access I now created a form showing data from the projects table.

What I want is to have a subform showing all persons- datasets which participate in this project. In this subform it should also be possible to add (or delete) persons from this project—a drop-down seems the best choice here.

How can I do this? I’m able to show all participants, but I’m not able to add them. seems like I have the “insert into view” problem again, since I need persons and persons_projects to show the correct datasets. but as I’m only changing/adding rows in a single table (persons_projects) I don’t see why access is bitchy again.

+1  A: 

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.

Remou
i want to have `persons` in the subform to display additional data (like addresses, phone numbers, etc.) guess i’ll need a subsubform then?
knittl
how can i access `project_id` from the row source query? i.e. only showing persons who still can be added—after all i want uniqueness. acess just doesn’t add those values without a error message (no clue what’s going on for non-techies)
knittl
adding a subsubform changes the default view to single form, but i need continuous forms for this to work properly. aaargh, access is driving me crazy …
knittl
You can select continuous forms as a propery of the subform (Format tab, Default View property). Please post some SQL for Row Source of the combo and of the subform. You will need to create a query that excludes those who have already been assigned to a project, this can be done by linking the junction table to itself.
Remou
I have added a little to my answer.
Remou
i tried using a join-query with both id’s from the junction table, but it still isn’t updatable.
knittl
Please post your SQL.
Remou
If you can get by with a datasheet, you can embed a subform in a main form, then switch the main form's view to datasheet, and the subform will appear as the subdatasheet. Other than that, it's impossible.
David-W-Fenton
Sorry, but what is impossible?
Remou
A: 

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.

Jeff O
i never want to delete persons, at all i only want to delete rows person-project junction table. basing the form on persons is also a way, but different semantics
knittl