Solved Child table not inheriting parent primary key autonumber value (1 Viewer)

Abes

New member
Local time
Today, 05: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?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:24
Joined
Feb 28, 2001
Messages
22,792
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.

 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 23:24
Joined
Jan 23, 2006
Messages
14,318
Can you post a graphic of your form(s)? Form/sub form Link criteria?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:24
Joined
May 7, 2009
Messages
16,394
on design view of your form, click on the subform.
on its Property Sheet->Data:

Link Master Field: theParentAutonumberFieldName
Link Child Fields: theChildForeignKeyFieldName
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:24
Joined
May 21, 2018
Messages
6,369
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:24
Joined
Feb 19, 2002
Messages
36,296
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

Top Bottom