Access: How to pass parameters to report when WHERE clause is embedded in complex SQL

感情迁移 提交于 2019-12-10 11:47:10

问题


I know the question of how to pass parameters has been asked a while back with the this Previous Stack Overflow question

However my situation involves SQL that is a bit more complex and cannot make use of the "where clause" filter available when opening a report. My SQL statement is an aggregate that produces a single row with one field for each aggregate. I have two parameters "@StartDate" and "@EndDate" that I need to pass into the query.

SELECT q1.CasesAssigned, q2.WarningsIssued  
FROM 
(SELECT COUNT(*) AS CasesAssigned 
FROM vwCaseDetail 
WHERE DateAssigned Between @StartDate AND @EndDate) as q1,  
(SELECT COUNT(*) AS WarningsIssued 
FROM vwWarningDetail 
WHERE DateIssued Between @StartDate AND @EndDate) as q2

What I would like to do is "popup" a dialog or small form to have the user enter the Start and End dates but I have no idea on how to pass the values into the query the report is based on. Any suggestions? Thank you.


回答1:


All you need to do is call the report from a form. On this form you have two text boxes for your start and end dates.

The query then has to be changed to

WHERE DateAssigned Between [Forms]![frmReporting]![txtDate_from] AND [Forms]![frmReporting]![txtDate_to]


来源:https://stackoverflow.com/questions/3855697/access-how-to-pass-parameters-to-report-when-where-clause-is-embedded-in-comple

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!