G
Guest
Could someone please show me to correct way to create a relationship in
Access. Everytime I create a relationship I get error messages
Access. Everytime I create a relationship I get error messages
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Beetle,
I am sorry for the lack of information, but it frustrates me everytime I
try
to create a relationship. I can create my two database two tables, for
instance Table A and Table B. I assigned a primary key to Table A and a
foreign key to Table B. So, I used your example. I made CustomerID as
the
primary key for Table A and OderDate as the primary key for Table B.
Therefore, OrderID will be the foreign key. When I tried to create a
relationship between the tables, I just get the join line and without the
one
to many symbols (no 1 for one or no 00 for many). What did I do wrong.
Or
tell me the correct way to do it.
primary key for Table A and OrderDate as the primary key for Table B.
Therefore, OrderID will be the foreign key.
If the two fields don't have the same name then Access will create the
relationship as 1 to 1.
Tom Wickerath said:Hi Beetle,
If the two fields don't have the same name then Access will create the
relationship as 1 to 1.
This is not a correct statement. A 1 to 1 relationship will be created if
you join two uniquely indexed fields, of compatible data types, together. You
would not want to attempt to join two Autonumber data types, because they
would be fighting against each other. But, you can certainly join an
Autonumber (or Text) field that is uniquely indexed [either by setting it as
a PK, or by indexing the field: Yes (No Duplicates)] to a corresponding
Number/Long Integer (or Text) field that is also uniquely indexed. This will
create the one-to-one relationship. The names assigned to the fields does not
matter, although, one should always avoid using any words that are considered
reserved words when assigning a name to anything in an Access application.
Problem names and reserved words in Access
http://allenbrowne.com/AppIssueBadWord.html
Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
Beetle said:If I'm reading your post correctly, you are trying to create a relationship
between a field named CustomerID and a field named OrderID. If the two fields
don't have the same name then Access will create the relationship as 1 to 1.
Let's take your example. Table A is the "One" side of the relationship, with
a primary key named CustomerID (let's presume it is an autonumber field),
and table B is the many side with a PK named OrderID (also an autonumber).
You would then add an additional field to table B and name it CustomerID with
a data type of Number (not autonumber). Then in the relationships window you
would drag the CustomerID field from Table A to the CustomerID field in table
B. Since the two fields have the same names, and compatible data types,
Access would create a one to many relationship.
BTW - it may not be the best idea to make OrderDate your primary key.
Typically OrderID would be the PK to keep each record unique. You could have
more than one order with the same order date.
HTH
use unique field names throughout a database.

myself to look at!

The foreign key field must be of
the same data type as the primary key it will connecting to in the
main table.
So, when you create the foreign key field, you make it a long
number field.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.