Re: Can't enter records through subform

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



What is the RecordSource of the subform:
- Same table as main form?
- Different table than main form?
- Query or SQL statement that involves several tables?
Is there are one-to-many relationship between these tables (Tools |
Relationships)? Is referential integrity enforced?

Open the main form in design view.
Right-click the edge of the subform control, and choose Properties.
What do you have for:
- Link Master Fields
- Link Child Fields
Normally, the master should be the primary key of the main form, and the
child is the foreign key of the related table.

If you have the relationships set up correctly, and the link fields right,
Access should assign the foreign key value for you. No code is needed.

There is one more scenario to take care of though. You can still get that
error if the main form is at a new record, and you try to enter a record in
the subform. To prevent this problem:
1. Open the child table in design view.

2. Select the foreign key field (the one that relates to the main table.)

3. In the lower pane, set the Required property to Yes, so it will not
accept a record without a foreign key value.

4. Still in the lower pane of table design, delete any 0 beside the Default
Value property.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Lorraine" <Lorraine@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:FEC3F37F-BB28-47CC-9A7E-C7072CFE60DD@xxxxxxxxxxxxxxxx
I have created a form (parent table) that also displays a subform (child
table). The child table is void of records at the moment but the parent
table has records. First I find a record in the parent table through the
form and then attempt to put a record in through the sub form but I get
the
following error message, "You cannot add or change a record because a
related
record is required in the parent table." Not sure if I need to put code
in
or what.

--
Lorraine


.



Relevant Pages

  • Re: Foreign key question
    ... then the children have two foreign key fields relating ... But each parent will also have only one first child, ... Eg you have a table of planes and a table of propeller types. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: LinkMaster>LinkChild problem
    ... created in the child table, but its ID had not been inserted in the ... key value of the related parent record - but parent records do not ... In this case, the Parent/Child structure is reversed, because Subform 2 ... a foreign key field does NOT have to have the same name as its' ...
    (microsoft.public.access.forms)
  • Re: using combo boxes to filter records in a subform
    ... one parent record. ... the first subform is bound to the parent table. ... the second subform is bound to the child table. ... just put the controls on the main form. ...
    (microsoft.public.access.forms)
  • Re: LinkMaster>LinkChild problem
    ... created in the child table, but its ID had not been inserted in the ... key value of the related parent record - but parent records do not ... In this case, the Parent/Child structure is reversed, because Subform 2 ... a foreign key field does NOT have to have the same name as its' ...
    (microsoft.public.access.forms)
  • Re: Cascading updates and NULL
    ... foreign key references between the parent and the child and use cascading ... a parent and a child. ... >> DataCol into the child table, cascading updates work fine. ...
    (microsoft.public.sqlserver.programming)