Solved Child table not inheriting parent primary key autonumber value

Abes

New member
Local time
Today, 09:24
Joined
Jul 2, 2021
Messages
21
I have a Parent- Child table relationship using a parent form and a child subform. The parent table has a autonumber field as primary key and this is linked to the same foreign key in the child table. I can enter a new record in the parent form and the parent table saves it, no problem there.
When I however enter a child record in the child form it saves it in the table with a value of 0 (zero) in the child table foreign key field i.e. the parent table autonumber field value is not being inherited by the child table.
If I manually go and change the value of the child table foreign key field to be the same as that of the parent table autonumber field then it (obviously) does show as in the child form as linked to the parent when I cycle through the records in the parent form.
In the table relationships view the relationship connection between the two tables is there.

What should I look out for, please?
 
You mention that there is a link to the foreign key. But where? Normally when you do sub-forms, there is a pair of properties where you specify the field in the parent that is the master's PK and the field in the child that is the child's FK to the parent. This article might help.

 
Can you post a graphic of your form(s)? Form/sub form Link criteria?
 
on design view of your form, click on the subform.
on its Property Sheet->Data:

Link Master Field: theParentAutonumberFieldName
Link Child Fields: theChildForeignKeyFieldName
 
master.jpg

As @arnelgp said. But the trick is to click on the outside subform control, and not on the form inside the control. I usually drag the mouse from the outside towards the control to get it.
 
When you create relationships using the relationship window, as you should, Access will automagically generate the master/child link when you add a subform to a form. If you have skipped the important step of enforcing referential integrity, you are on your own in more ways than one.
 

Users who are viewing this thread

Back
Top Bottom