Creating relationships between tables

R

Rachel

I have a Projects Table and a Customers Table. My problem is I want to have
multiple Customers on one project and I want each customer to be able to have
multiple projects. I don't know how to set up the tables and relationships to
do this.
 
S

Steve

You need three tables:

TblProject
ProjectID
etc

TblCustomer
CustomerID
etc

TblProjectCustomer
ProjectCustomerID
ProjectID
CustomerID

For data entry you need a form/subform. The main form would be based on
TblProject and the subform would be based on TblProjectCustomer. In the
sobform you need a combobox (or listbox) to enter CustomerID. The row source
for the combobox (or listbox) would be TblCustomer.

Steve
(e-mail address removed)
 
T

tina

you're describing a classic many-to-many relationship: one customer may be
involved in many projects, and one project may involve many customers. in
relational design, you model this relationship by using a "join" or
"linking" table, which is the "many" side of a one-to-many relationship with
each of the other two tables, as

tblProjects
ProjectID (primary key)
<other fields that describe a project, but nothing about customers.>

tlbCustomers
CustomerID (pk)
<other fields that describe a customer, but nothing about projects.>

tblProjectCustomers
ProjectID (foreign key from tblProjects)
CustomerID (fk from tblCustomers)
<you can use the two fields as a combination primary key; or you can use a
separate field (probably Autonumber) as the primary key, in which case you
need to set a Unique multi-field index using both foreign key fields.>

the relationships are
tblProjects.ProjectID 1:n tblProjectCustomers.ProjectID
tblCustomers.CustomerID 1:n tblProjectCustomers.CustomerID

set these relationships in the Relationships window, and make sure you
enforce Referential Integrity on each relationship.

so each customer involved with a specific project will be a single record in
tblProjectCustomers. recommend you read up/more on relational design
principles so you'll understand how the relationships work. for more
information, see
http://www.accessmvp.com/JConrad/accessjunkie/resources.html#DatabaseDesign101

hth
 
B

Bernard Peek

Rachel said:
I have a Projects Table and a Customers Table. My problem is I want to have
multiple Customers on one project and I want each customer to be able to have
multiple projects. I don't know how to set up the tables and relationships to
do this.

As others have already pointed out, the answer is to create a link
table. I'll just add that it's worth taking some time to look at what
the link table actually represents. You may find that there is more to
it than just the keys to its two parents.
 

Ask a Question

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.

Ask a Question

Top