Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1701
  • Last Modified:

How to create a Microsoft Access One to Many Relationship

I know I'm being silly, but I am completely stumped!  I have an Access database where I want to store manufacturers and their products.  I have two tables, the first (tblManufacturer) has three fields: an autonumber field which is the record ID (and Primary Key), a field for Manufacturer name and a Lookup field for the products they produce.  The second table (tblProduct) has three fields: an autonumber field which is the record ID (and Primary Key), a Lookup field which looks up the Manufacturer from the first table, and a product field.

What I want to do is look at a manufacturer in the Manufacturers table and click the lookup to see what products they produce.  Currently, when I do this, I get a list of ALL products in the Products table, regardless of their manufacturer.  I have tried everything I can think of and just about every combination of relationships, but I only ever get all records.  At the moment, I have a one to many relationship set between the ID field in the Manufacturers table and the Manufacturer field in the Product table set to include only those records where both fields match.

An example is: Manufacturer ACME has a record ID of 6 - In the lookup in the Products table, the record equals 6.  When I select the lookup in the Manufacturers table, I don't just see products relating to ACME, but I see all products, regardless of their manufacturer.

Please help!!
0
Alex3471
Asked:
Alex3471
1 Solution
 
TextReportCommented:
You can't have the Product in the Manufacturer's table as this will mean that 1 manufacturer can only product 1 product. If more than 1 Manufacturer can produce a product then you need to do a Many to Many relationship. This is done with 3 tables

tblManufacturer: ManufacturerID as PK
tblProducts: ProductID as PK
tblManufacturerProducts: ManufacturerID and ProductID as joint PK

Cheers, Andrew
0
 
Jeffrey CoachmanMIS LiasonCommented:
As TextReport stated.

In the most basic sense your tables would look something like this:

tblManufacturers
ManufacturerID (Primary Key)
ManufacturerName
ManufacturerCountry
...ect

tblProducts
ProductID (Primary Key)
ManufacturerID (Foreign Key)
ProductName
ProductPrice
...ect

The should be related on ManufacturedID in the relationship window.

If this is done, it will create little (+) symbol in the Manufatures table.
Clicking the "+", will display all the products that that manufacture makes.

You can then use the form wizard to create a main form/ subform
Selecting a Manufacturer in the main form displays all the corresponding Products.

Here is a sample.
Examine it carefully.

I am sure you can modify it to work in your Database.
;-)

(But also as TextReport states, this gets a bit more complicated if one product can be made by more than 1 Manufacturer.)

JeffCoachman

db179.mdb
0
 
Alex3471Author Commented:
Perfect!!  Got me out of a dreadful hole!  Thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now