Search code examples
ms-accesscombobox

In MS Access combo box,how to use form value as where class


I am using following query in combo box for display data from table based on form text box field as parameter but combo box is not displaying data. Please note that itemid field in main item table is string.

SELECT [Item].[ID], [Item].[ItemCode], [Item].[ItemName], [Item].[Price_USD], 
[Item].[Price_GBP], [Item].[Price_THB], [Item].[Price_AED], [Item].[Price_AED_VAT], 
[Item].[Price_SAR], [Item].[Price_SAR_WHT], [Item].[Hogan_Cost_USD] 
FROM Item WHERE [ItemCode]='Forms!Order_Detail subform!itemid'; 

Solution

  • If this is a query object, then must reference subform through parent form and subform container control. I always name container different from the object it holds, such as ctrDetails
    WHERE [ItemCode]=Forms!parentformname!ctrDetails.Form!itemid;

    If this SQL statement is directly in combobox RowSource and combobox is on subform along with the textbox, just reference textbox directly. I always name controls different from fields, such as tbxIC:
    WHERE [ItemCode]=[tbxIC]

    Are you pulling in every field from Item table? If so, could shorten the SQL with wildcard:
    SELECT * FROM Item WHERE [ItemCode]=[tbxIC];