The error message tells you where the problem is. tblCustomers ([Last Name]) is not unique but part of a composite PK. So you cannot create a relationship. Make lastname a unique field and it should then work - but then you can only have one customer with a last name of 'Smith'.
ALTER TABLE tblInvoices
ADD CONSTRAINT FK_Test FOREIGN KEY ([PK]) REFERENCES tblCustomers ([PK])
The Link I posted in post #40 has examples of both of the above, what have you tried and what is the error?Thank you Pat for good lesson for me.
I know that relationship is wrong.
I only need technical solution how to write Access SQL to create composite key relationship plus 1 to 1 relationship.
And if this is possible?
Best
Jacek
Sub CreateTableX1()
Dim dbs As Database
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = CurrentDb
On Error Resume Next
sqlS = "ALTER TABLE tblCustomers DROP CONSTRAINT NewOne"
dbs.Execute sqlS
On Error GoTo 0
sqlS = "ALTER TABLE tblCustomers ADD CONSTRAINT NewOne FOREIGN KEY (LastName) REFERENCES tblInvoices (LastName) "
' Create a table with two text fields.
dbs.Execute sqlS
End Sub
Sub CreateTableX1()
Dim dbs As Database
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = CurrentDb
On Error Resume Next
sqlS = "ALTER TABLE tblCustomers DROP CONSTRAINT NewOne"
dbs.Execute sqlS
On Error GoTo 0
sqlS = "ALTER TABLE tblCustomers ADD CONSTRAINT NewOne FOREIGN KEY (LastName) REFERENCES tblInvoices (LastName) "
' Create a table with two text fields.
dbs.Execute sqlS
End Sub
sqlS = "ALTER TABLE tblCustomers ADD CONSTRAINT NewOne FOREIGN KEY (FirstName,LastName) REFERENCES tblInvoices (FirstName,LastName) "