Many to many relathionship filter?

C

ChrisPapad

I have 3 tables as follows:

Products (ID,Name)
Categories (ID,Name)
ProductCategory (ID,CategoryID,ProductID)

There is a many to many relationship between Products and Categories.

How could i filter the products shown in a form by category or
categories? Is there a standard practice?

Chris
 
A

Allen Browne

The Filter of the form can be anything you can use in the WHERE clause of a
query. You are allowed to use a subquery in the WHERE clause, so you can use
a subquery as the Filter of your form.

This example assumes a form bound to the product table (no reference to
categories anywhere), but filters to form to those products in cagegories 3,
6, and 99:

Me.Filter = "EXISTS (SELECT ProductID FROM ProductCategory WHERE
((ProductCategory.ProductID = Products.ID) AND (ProductCategory.CategoryID
IN (3, 6, 99))))"
Me.FilterOn = True

If subqueries are new here is Microsoft's introductory article:
How to Create and Use Subqueries
at:
http://support.microsoft.com/?id=209066
 
C

ChrisPapad

Allen said:
The Filter of the form can be anything you can use in the WHERE clause of a
query. You are allowed to use a subquery in the WHERE clause, so you can use
a subquery as the Filter of your form.

This example assumes a form bound to the product table (no reference to
categories anywhere), but filters to form to those products in cagegories 3,
6, and 99:

Me.Filter = "EXISTS (SELECT ProductID FROM ProductCategory WHERE
((ProductCategory.ProductID = Products.ID) AND (ProductCategory.CategoryID
IN (3, 6, 99))))"
Me.FilterOn = True

If subqueries are new here is Microsoft's introductory article:
How to Create and Use Subqueries
at:
http://support.microsoft.com/?id=209066

Got it!Thanks!

Chris
 

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