Re: Can't enter records through subform
- From: "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
- Date: Fri, 23 Jun 2006 11:20:35 +0800
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
.
- Prev by Date: Re: After Update Move Focus to Subform
- Next by Date: Re: Creating a chart - help
- Previous by thread: Re: Summing up Text Boxes that are based on expressions
- Next by thread: Re: passing values between forms
- Index(es):
Relevant Pages
|