Rex
asked on
How can a Pass a Parameter (like a month and year mm-yyyy) to multiple queries in a macro?
I have multiple queries that I run via a Switchboard button for monhtly reporting. I would like to be able to enter the date mm-yyyy only once and have this passed to each query that needs it as that query runs.
I am using the following code to run the queries (this is an example of one)
DoCmd.OpenQuery "KO_QN_EFR_A_Product_Sum_M onthly", acViewNormal, acEdit
Can someone show me/ tell me how to do this? Thank you.
I am using the following code to run the queries (this is an example of one)
DoCmd.OpenQuery "KO_QN_EFR_A_Product_Sum_M
Can someone show me/ tell me how to do this? Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Rather than open the queries in a recordset view, why not open a separate form (datasheet view) and control the specific records with a Where clause in the DoCmd.OpenForm method. If the field content for each query is different, we have a problem.
ASKER
thank tou for your suggestions. I'm not sure I was clear. essentially, I have a series of queries that prompt me for the month and year as below. I was wondering how I could enter that once, and have the subsequent queries use the information already entered, so that I only had to do it once.
Parameter-Prompt.jpg
Parameter-Prompt.jpg
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If the entered year-month combination is used as a query criterion, you can use my code (posted earlier) to save this value to a custom db property, and then use it as a criterion in the query -- just put GetProperty("PropName", "") in the Criteria line of the appropriate field in the query, and remove the query parameter, as it is no longer needed.
Can you tell me what kind of queries are in the lot?
ASKER
Here's an Example of one. It creates a two column table for use in feeding a Pareto chart.
SELECT (KO_QN_Data.Field20)+' ('+[KO_QN_Data.Code group]+')' AS Defect, Sum(CLng(TransformTextFields([KO_QN_Data.DefectQty (ext)]))) AS QTY INTO KO_QN_EFR_B_Product_Pareto_Monthly_Table
FROM KO_QN_Data
WHERE (((Format([Created On],"yyyy-mm"))=[yyyy-mm]) AND ((KO_QN_Data.[Short text for code])="Kimball Office Furniture") AND ((GetBucket([Code group]))="Product") AND ((GetNOFGSA([Product Hierarchy]))="Not NOF GSA"))
GROUP BY (KO_QN_Data.Field20)+' ('+[KO_QN_Data.Code group]+')'
ORDER BY 2 DESC , 1;
In addition, my code assumes that the parameter in each query is written: [yyyy-mm] - ie. bracketed. If not bracketed, remove the brackets from the Replace() line.
Then my code should work well with that. You just have to enter the query names in the arrQryNames line in place of qryName1, qryName2, etc.
I see an error:
DoCmd.RunSQL arrQryNames(i)
should be:
DoCmd.OpenQuery arrQryNames(i)
DoCmd.RunSQL arrQryNames(i)
should be:
DoCmd.OpenQuery arrQryNames(i)
ASKER
Thank you both. I went a slightly different route, but both of your solutions helped me arrive there. I really do appreciate it. Thank you.
Rex
Rex
Thanks, glad to help.
Or you can run your queries directly like this:
Currentdb.Execute "Your SQL Here WHERE SomeValue = " & Me.Somevalue
"Your SQL Here" would be the SQL needed for your queries ... you can get that by opening your query in Design view, and then click View - SQL.