I have posted this question on the "Access - other" forum, but am trying it here also to see if I might find somebody who has seen this before. I am stumped.
I have a "master" table with a primary key. There are two related tables with the same pk. If I create a query to get all records from the master and any in the one-to-one related files it works as expected, but something strange happens on data input. Here is a condensed version of the scenario.
Table1 f1 is autonumber & primary key
f2 is text
Table2 f1 is long & primary key
f2 is text
Table3 f1 is long & primary key
f2 is text
Using Access 2000 relations, set Table1 related to Table2 on Table1.f1=Table2.f1, which is a one-to-one relationship. Set join type to LEFT JOIN. Enforce referential integrity.
Set Table1 related to Table 3 on Table1.f1=Table3.f1, which is also one-to-one and join type to LEFT. Enforce referential integrity.
Now create a query as:
SELECT Table1.*, table2.f2, Table3.f2
FROM (Table1 LEFT JOIN table2 ON Table1.f1 = table2.f1) LEFT JOIN Table3 ON Table1.f1 = Table3.f1;
Now run the query. Enter Table1.f2, Table2.f2 and Table3.f2. Try to save. Error message is "You cannot add or change a record because a related record is required in Table "Table1". It doesn't work. BUT if you enter the fields Table2.f2 and Table3.f2 first, then Table1.f2, it saves with no problem.
By including the key fields, Table2.f1 and Table3.f1 in the query, I can see that if I enter Table1.f2, Table2.f2 and then as soon as I enter Table3.f2, the key field Table2.f1 changes to a ZERO. (huh?) This is why the error occurs, because the key field of Table2 is now ZERO, which has no related parent in Table1 and therefore violates referential integrity.
I have duplicated the problem by creating the three simple tables exactly as described above and the result is the same - If I enter data in Table1 first, which autonumbers the key field, I can then enter info into either related table with no problem. But when I try to enter into the second related table the pk of the first related table changes to a zero. Any help would be appreciated.
Oh, and I have tried various changes to the SQL of the query - including changing it to all INNER JOINS, just for a test, and the result is the same. The problem seems to lies to having two one-to-one relations hanging off the pk of the "master" table. Any help would be greatly appreciated. I hate to resort to using code to populate pk when the referential integrity should be insuring this. Thanks for reading this far! Regards.
I have a "master" table with a primary key. There are two related tables with the same pk. If I create a query to get all records from the master and any in the one-to-one related files it works as expected, but something strange happens on data input. Here is a condensed version of the scenario.
Table1 f1 is autonumber & primary key
f2 is text
Table2 f1 is long & primary key
f2 is text
Table3 f1 is long & primary key
f2 is text
Using Access 2000 relations, set Table1 related to Table2 on Table1.f1=Table2.f1, which is a one-to-one relationship. Set join type to LEFT JOIN. Enforce referential integrity.
Set Table1 related to Table 3 on Table1.f1=Table3.f1, which is also one-to-one and join type to LEFT. Enforce referential integrity.
Now create a query as:
SELECT Table1.*, table2.f2, Table3.f2
FROM (Table1 LEFT JOIN table2 ON Table1.f1 = table2.f1) LEFT JOIN Table3 ON Table1.f1 = Table3.f1;
Now run the query. Enter Table1.f2, Table2.f2 and Table3.f2. Try to save. Error message is "You cannot add or change a record because a related record is required in Table "Table1". It doesn't work. BUT if you enter the fields Table2.f2 and Table3.f2 first, then Table1.f2, it saves with no problem.
By including the key fields, Table2.f1 and Table3.f1 in the query, I can see that if I enter Table1.f2, Table2.f2 and then as soon as I enter Table3.f2, the key field Table2.f1 changes to a ZERO. (huh?) This is why the error occurs, because the key field of Table2 is now ZERO, which has no related parent in Table1 and therefore violates referential integrity.
I have duplicated the problem by creating the three simple tables exactly as described above and the result is the same - If I enter data in Table1 first, which autonumbers the key field, I can then enter info into either related table with no problem. But when I try to enter into the second related table the pk of the first related table changes to a zero. Any help would be appreciated.
Oh, and I have tried various changes to the SQL of the query - including changing it to all INNER JOINS, just for a test, and the result is the same. The problem seems to lies to having two one-to-one relations hanging off the pk of the "master" table. Any help would be greatly appreciated. I hate to resort to using code to populate pk when the referential integrity should be insuring this. Thanks for reading this far! Regards.