Problem with saving data to related tables

rclarke

Registered User.
Local time
Today, 22:36
Joined
Jul 13, 2012
Messages
24
Hello, I was hoping one of you kind people might help. I have come undone trying to simplify my access database. I have a built a database to record and collate info about clinical trials that are run within my department. I have one large table [Trial Info] which contains all trial info and have created a second and third table [Milestones] & [Comments] to collect dates of various milestones and a notes that occur throughout the course of a study.

The milestones (dates) are recorded in the 2nd table and the comments are recorded in the 3rd table.

All data is entered by staff on forms. The first form captures basic info about the study, once this has been entered, the idea is to click a button to open the second form to document the trial milestones, this form also contains a subform for listing any free text comments required during the life of the study which are stored in the 3rd table.

I have setup the relationships between tables as best I can.

The main table with basic trial info is the parent table, linking the primary key to the foreign key in the second table, the foreign key of the third table is related to the primary key in the second table so these tables should be looking up the correct clinical trial as far as I can tell.

The form containing data from the main table has a button which I have set to open the Milestones & Comments form, and I have set this to open to the record that relates to the record in view in the primary form. The primary key is related to the foreign look-up key in the milestones table.

This opens the form fine, however this is not updating the foreign look-up key, this remains '0' which I assume is the cause of the following error when I try to save changes to the record

You cannot add or change a record because a related record is require in table 'Trial Info'

How do I trigger the foreign key to update to the primary key so that the first time a milestone page is opened for a new study it creates a matching record?

I read elsewhere that this error means that relationships have been entered the wrong way around, either I am barking up the wrong tree, am asking access to do something impossible or have taken the wrong approach.

I hope that makes some sort of sense? I would appreciate any suggestions as this is a major headache!
 
What version of access are you using?
Can you post a jpg of your tables and relationships?
 
Hi, I'm using Access 2003.

Actually I was able to get around this issue by placing the milestones and comments forms in a subform within the main form, that way the foreign key was automatically entered in the related tables. Is this a limitation of access or are there means of doing this for separated forms?

My fix works much better overall as it has lead to a redesign that I actually prefer to my original layout.
 
It sounds like a feature of Access designed to protect referential integrity has guided you to a better form design. Good work. :)
 
Glad you have it sorted.

You cannot add or change a record because a related record is require in table 'Trial Info'
This sort of error in conceptual terms occurs when you try to add a child, but you have not identified any parents.
 

Users who are viewing this thread

Back
Top Bottom