I want to be able to choose an item from a drop down list (based on a query i.e. distinct products) and have the item chosen to be automatically used as a parameter in another query.
to use the drop down list as a parameter in another query, in the second query you would need to put this into the criteria of the field you are filtering on: -
Thanks for your input but I can’t get it to work. Do I need to put an on_click or an After_update event in the first box to run the second query (qrysum) and populate the second list box.
Here is my setup below.
I have a form called frmsearchNew.
I have a combo box called pickpart to give a list of distinct part numbers.
(This list box is based on a simple select distinct query).
User should be able to select a part no in the first combo box and the chosen part will be used in a second query whose results will be displayed in a list box in the same form.
The second query is called qrySum
I have put in the code you suggested [forms]![frmsearchNew]![pickpart] in the field required – see SQL below - but I get nothing returned from the query no matter what part I choose. When I try the query with out this line
HAVING (((tblstock.[MaterialPart#])=[forms]![frmsearchNew]![pickpart])) I get all the data.
Example with line
SELECT tblstock.[MaterialPart#], tblstock.[Lot#], tblstock.Location, Sum(tblstock.Qty) AS SumOfQty
FROM tblstock
GROUP BY tblstock.[MaterialPart#], tblstock.[Lot#], tblstock.Location
HAVING (((tblstock.[MaterialPart#])=[forms]![frmsearchNew]![pickpart]))
ORDER BY tblstock.[MaterialPart#] DESC;
Query minus line which gives all data
SELECT tblstock.[MaterialPart#], tblstock.[Lot#], tblstock.Location, Sum(tblstock.Qty) AS SumOfQty
FROM tblstock
GROUP BY tblstock.[MaterialPart#], tblstock.[Lot#], tblstock.Location
ORDER BY tblstock.[MaterialPart#] DESC;
You may try this in the AfterUpdate event of the pickpart control:
[name of 2nd list control].RowSource = "SELECT [MaterialPart#],[Lot#],Location" _
& ",Sum(Qty) AS SumOfQty FROM tblstock" _
& " WHERE [MaterialPart#]='" & [pickpart] & "'" _
& " GROUP BY [MaterialPart#],[Lot#],Location"
If MaterialPart# is defined as numeric in tblstock then get rid of the single quotes.
Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.