Results 1 to 4 of 4
  1. #1
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105

    Question What query to filter dropdown on subform

    Thank you for reading my post, I'm still pretty new to Access so I appreciate your help.

    Setup:
    I have 3 relevant tables...


    Customer
    Product
    Customer Product Join Table

    I have a customer form with a subform for detail of products that the customer has purchased (the join table), and the user can also add additional items to the customer via that sub form.
    My products table has a checkbox legacy/not legacy.

    I want to design a query to populate the sub form products field such that if they add a new entry the only options presented are items where tblProducts.Legacy = False.
    However, if a customer owns a legacy product (Quantity > 0) display that product in the sub form...

    Hopefully I'm explaining this properly... Please let me know what further details you need, or if you need example tables/forms.

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    something like

    Code:
    SELECT ProductPK, ProductName 
    FROM tblProducts
    WHERE Legacy=False OR ProductPK IN (SELECT ProductPK FROM tblProducts AS P INNER JOIN tblCustProdJoin ON P.ProductFK=tblCustProdJoin.ProductFK WHERE P.Legacy=True AND tblCustProdJoin.CustomerFK=[CustPK])
    [CustPK] refers to a control on your form which contains the CustomerPK

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Code in the combobox GotFocus event to set the combobox RowSource property and requery the combobox.

    Me.comboboxname.RowSource = "SELECT * FROM Products" & IIf(IsNull(Me.comboboxname), " WHERE Legacy=False", "") & ";"
    Me.comboboxname.Requery
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    sstiebinger is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    105
    Thanks for the replies...

    After discussing the case use for this combobox, and multiple different scenarios, we decided that it's actually preferable to show all items, regardless of legacy.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-25-2013, 08:35 AM
  2. Replies: 6
    Last Post: 11-15-2012, 02:38 PM
  3. Subform tied to dropdown box?
    By BillC in forum Forms
    Replies: 13
    Last Post: 08-24-2012, 01:53 PM
  4. Replies: 1
    Last Post: 08-16-2012, 01:51 PM
  5. Replies: 6
    Last Post: 05-05-2012, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums