ms-accessdatabase-designrelational-databasems-access-2013erd

Cannot add or change a record because a related record is required in table 'COMPANY'


I think my Contact List database design is correct, but there is an error. Access 2013 is telling me:

You cannot add or change a record because a related record is required in table 'COMPANY'

I'm new to Access and this is for a class called "Computer Concepts II". I've already done my assignment, and followed the instructions meticulously. This course is held online only and I have tried 3 times in 3 different ways but haven't been able to get any feedback from the instructor.

Here is the breakdown of the things I have tried:

Business Rules

  1. A person must have only one family, but a family can have many people.
  2. A person can work for one or zero companies.
  3. A company can have zero or many people.
  4. For MS Access purposes PERSON is the strong table.

MY ERD Diagram

Eric Hepperle's ERD for Contact List Database in Access 2013

BUILT THE TABLES

  1. Built PERSON table.
  2. Built COMPANY table.
  3. Built FAMILY table.

CREATED RELATIONSHIPS

  1. Created relationships between tables (see screenshot attached). For optionality, set PERSON as the "strong" table.
  2. Originally had ID-FAM and LNAME fields in FAMILY table as both required and indexed.
  3. Originally had ID-PER, ID-FAM_FK, & ID-COM_FK in PERSON table as indexed.
  4. Originally had ID-COM as the only indexed and required field in COMPANY table.

ENCOUNTERED 'RELATED RECORD' ERROR WHILE ENTERING DATA IN PARENT TABLE

"You cannot add or change a record because a related record is required in table 'FAMILY'"

Well, a COMPANY entry is completely optional and not required in any way, so that's a bit confusing. I'm not sure what I'm doing wrong or where to go from here. I did not know how to use Access before this class but I think I have a pretty good handle on it now, and I've followed the instructions meticulously. Thus, I believe the issue is a misconfigured setting somewhere.


Solution

  • There should be no value in the Default property field.

    Access was automatically setting a default value for my foreign keys of zero ("0"), even though a person wasn't required to have a company. "0" in the company field for my person record was causing the error.

    I suspect that the database was looking for a company record with an ID of "0" and because my company records start at 2 the "0" record was never found, causing the error.

    The solution is to go into the default field for my 2 foreign keys in the design view, delete the zeros, and make sure there are no default values. In other words, ensure there are no default values for foreign keys.

    I was able to add 3-4 rows of data for each table and run a basic query to test the database. It seems to be working.