Auto populate related primary Key (1 Viewer)

Gueven

New member
Local time
Today, 23:25
Joined
Jun 8, 2021
Messages
2
Hello,

I am creating a database right now and I have a table with a Primary Key that is linked to another table with a 1 to 1 Relationship.

I created a query and used all the fields that I wan´t to edit with a form.

My problem is, if i don´t fill a field, that is linked to the second Table with the primary Key, and I Save the record, I can´t edit the fields that are linked to the second table anymore, because the primary key for the second table wasn´t generated.

So I thought I could autofill the forgein keys, but it is harder than I thought.

Does anyone know a way to do that?
 

Minty

AWF VIP
Local time
Today, 22:25
Joined
Jul 26, 2013
Messages
10,371
Whilst not totally wrong - there are very few legitimate reasons to have a 1 to 1 relationship.
Perhaps you could explain the tables and briefly the data you are attempting to manage.

As to your problem, I suspect it is because you need to set up the child/master relationship in the form and use a subform limited to display one record.

A query won't magically create a matching PK ID, ideally one needs to be a PK and the other an FK otherwise you can't ever add a record to either table.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:25
Joined
May 7, 2009
Messages
19,237
why 1 on 1, when you can have it all in 1 table.
use Query and Left join the other table and not use Inner Join.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:25
Joined
Feb 19, 2002
Messages
43,266
In a 1-1 relationship, the primary table has an autonumber PK but the PK of the child table is a long integer just as it is with all other foreign keys.

1. What is the point of the 1-1?
2. The child table should be a subform, NOT part of the main form otherwise - what is the point of the 1-1?
3. Set the relationships properly in the relationship window and Access will automagically relate the master/child forms according to the defined relationship.
5. As arnel suggested, use a Left Join when you join the two tables.

and not to repeat myself, what is the point of the 1-1? They are extremely rare in the real world.
 

Gueven

New member
Local time
Today, 23:25
Joined
Jun 8, 2021
Messages
2
Hey thanks for the answers,
I decided to combine the tables in one table.
I already used left joins the displaying of information was not the problem, the edtiting the second table after a save was.
Anyway seems like a 1-1 Relationship just makes it harder to use queries.

Thanks
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:25
Joined
Feb 19, 2002
Messages
43,266
A 1-1 relationship is no harder to use than a 1-m. But it sounds like you didn't actually have a 1-1 to begin with so you are better off with a single table.
 

Users who are viewing this thread

Top Bottom