[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Filter Based on Value in Subform

Posted on 2012-04-01
5
Medium Priority
?
341 Views
Last Modified: 2012-05-06
We have a primary form of products with a Subform called Products_Pricing that is a one-to-many.  In the subform there is a filter that has the CustomerID.  How can we filter the primary form based on the Subform value???  

For example, there are 500 total products, but some products are sold to Customer A and some are sold to CustomerB, whereas some are sold to both customers.  Our subform has a customer field.  If the users use the built in filter, then it just filters the customers within the "one product".  So if CustomerA has pricing set for 40 products, they want to be able to say just show me Customer A Active Products.
0
Comment
Question by:sharpapproach
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 37794031
It sounds like the subform is constrained by the main form -- probably with a master-child relationship.  That's a common design and very powerful, at that, because it does a lot of things automatically (read that: no programming required).  If do not want the sub-form constrained by the main form, then you need to eliminate the master-child relationship that is declared in the properties of the subform control.   Understand though, in so doing, you lose the automated nature of the master-child relationship.   Specifically, you need to programmatically constrain the child form to the parent form if you want that behavior or programmatically filter the child form on customer without regard for the context of the main form if that is the behavior you want.  

Rather than using filters, I would steer you toward manipulating the recordsource of the parent form based on the values selected in the subform.  It is much the way you might manipulate the recordsource of the parent form based on a combo box selection.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 37794886
It doesn't seem that you can Filter the main form, because (I am guessing) there would not be a customer value available to use in a filter.
So this becomes a little more tricky.

When you want products for a given customer, you will have to use code in the subform to change the recordsource for the main form to a query which will be something like..

Dim strsql as string
strsql = "Select Products.* from Products as P Inner Join [Products_Pricing] as PP "
strsql = strsql & " On P.ProductId= PP.ProductID "
strsql = strsql & " Where PP.CustomerID= " & me.Customerid
me.parent.recordsource = strsql

In my opinion, you should expect users to want to filter or not filter the subform, independently of whether the main form is 'filtered' or not so you should use a button on the subform to trigger the main form change, using the code above.  (the code I indicated will not work in the main form).

And I expect you will also need a button on your main form to show all products again.

Me.recordsource = "Products"
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37796322
<How can we filter the primary form based on the Subform value???  >
As Pete states, trying to filter a main form from a value in a sub form is not commonly done.
You are basically asking too much of the basic main/subform design.
If your Main form is Products and your subform is "Product Pricing", then you could create another form (Pop-up form or a sub-subform) to display specific pricing for a certain customer.

Or, better, ...create a main form for the customer, then filter that customer's pricing in a subform.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37796338
...just a note.

Your system here would also need a facility for tracking "Price History...

Note that as prices change, in some cases you will need to look up the "Old" price, in other cases you will need the "Current Price"...

...but you may want to post this as a separate new question...

JeffCoachman
0
 
LVL 42

Accepted Solution

by:
dqmq earned 1500 total points
ID: 37796858
To be clear,,,let's suppose you have a main form that shows all products.  When you select a product, a subform displays all pricings (and implicitly customers) for the selected product.  Now, you want to select one of the customers and then refresh the main form with only products associated with that customer.  

I think that's achievable.

1.  add an (invisible?) llistbox to the main form to hold customerid

2.  Change the record source of the main form to a query having this form:
 select * from products p where exists
    (select * from products_pricing pp where pp.productID = p.productID and pp.customerID = nz(yourcustomerlistbox,pp.customerid)

At this point, your main form should work the same as it does now.

3. In the on_current event of the subform, add some code like this:
   yourcustomerListbox=me.customerid
   yourmainform.requery

Now the mainform should be reduced to only products by the selected customer

4. You may need a few other lines to polish things up.  Like re-establishing the selected product and customer.  Like starting over with all products, etc.  But let's get to those refinements later after you have the basic concept working.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question