views:

39

answers:

1

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.

+2  A: 

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]
Kevin Ross
This worked great! This allows me to validate the user input before passing it to the report. Now I just have to figure out why the report open and closes by itself. I launch the report after clicking an "OK" button when all values have been entered. Perhaps that is for another question :) Thanks Kevin!
webworm
I added another stack overflow question that address the issue .. http://stackoverflow.com/questions/3856261/how-to-collect-input-via-a-form-and-pass-to-report-query-in-access
webworm
As I suggested in a comment in that other question, you might consider opening the form in the report's OnOpen event and setting the report's Recordsource with the appropriate WHERE clause.
David-W-Fenton