Results 1 to 5 of 5
  1. #1
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55

    Drop downs that link together in Forms

    I have limited Access knowledge but I'm trying to build a very basic form where there are 5 fields. I've used Combo boxes so 2 of the fields are drop downs from 2 other tables. However I want the second drop down to be dependent on the first as I'm going to have a lot of data in this database and want to segment it so when I click on the second drop down it won't bring up everything, just what is associated from the first table. Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    the query of combo2 (cities) looks at combo1 (states) to filter.
    cboCity query = qsCities1State
    qsCities1State : select City from table where [state]=forms!fMyForm!cboState


    you just need to refresh the next box after user picks an item in the combo...


    Code:
    sub cboState_AfterUpdate()
     cboCity.requery
    end sub

  3. #3
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    hi there, thank you for your reply. I really have very limited knowledge, where would I put this code, in the form? I am basically creating a stock inventory database and have a list of products and then a category associated with those products in a table, then another table which has all the stock in/stock out transactions. I've created a form from this transactions table but want to have a drop down of category and then the second drop down where you select the stock to be taken from will be based on the category thats in the products table. thank you!

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by CP611 View Post
    hi there, thank you for your reply. I really have very limited knowledge, where would I put this code, in the form? I am basically creating a stock inventory database and have a list of products and then a category associated with those products in a table, then another table which has all the stock in/stock out transactions. I've created a form from this transactions table but want to have a drop down of category and then the second drop down where you select the stock to be taken from will be based on the category thats in the products table. thank you!
    This is a very common subject of enquiry. Have a search for Cascading Combos. If you post a copy of your db we may even be able to sort it out for you.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Join Date
    Apr 2017
    Posts
    1,681
    Two ways to achieve same without cascading combos:
    a) You have lookup tables tblProducts:ProductID, ProductName, ... and tblCategories: CategoryID, CategoryName, ... You create a table tblProductCategories: ProductCategoryID, ProductID, CategoryID. In your form's soutce table/cuery, instead of fields for ProductID and CategoryID, you have a single field ProductCategoryID. And for form you create a single combo linked to ProductCategoryID, with row source like
    Code:
    SELECT pc.ProductCategoryID, p.ProductName & ": " c.CategoryName As ProductOfCategory
    FROM (tblProductCategories pc INNER JOIN tblProducts p ON p.ProductID = pc.ProductID) INNER JOIN rblCategories c ON c.CategoryID = pc.CategoryID'
    ORDER BY 2
    b) You create a table tblProductCategoryID like above, but in source table/query of your form you have fields for ProductID and CategoryID. You create a combo linked to ProductID. You create text/combo box linked to CategoryID, and set the text box either hidden or disabled (You use combo in case it will be only disabled, so user sees category name instead of it's ID. But having this control visible will be abundant, as the first combo shows both product name and it's category anyway). The main combo will have the row source like
    Code:
    SELECT p.ProductID, c.CategoryID, p.ProductName & ": " c.CategoryName As ProductOfCategory
    FROM (tblProductCategories pc INNER JOIN tblProducts p ON p.ProductID = pc.ProductID) INNER JOIN rblCategories c ON c.CategoryID = pc.CategoryID'
    ORDER BY 3
    ForCombo, you create an AfterUpdate event, which writes CategoryID into hidden/disabled text box (As I myself never have tried this, I'm not sure about exact syntax here).

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

Similar Threads

  1. Combo Box Drop-Downs
    By victor2525 in forum Access
    Replies: 6
    Last Post: 03-05-2018, 04:08 PM
  2. Drop downs error on clear
    By Ruegen in forum Programming
    Replies: 2
    Last Post: 10-31-2013, 12:40 AM
  3. database design: conditional drop-downs?
    By sebeckett in forum Access
    Replies: 5
    Last Post: 09-05-2011, 12:46 PM
  4. Collecting data via email with drop downs
    By tlyons in forum Access
    Replies: 2
    Last Post: 01-19-2011, 10:34 AM
  5. Drop downs and serching in subforms
    By joelwebster in forum Forms
    Replies: 0
    Last Post: 12-13-2009, 03:38 PM

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