I have an Access 2003 MDB where I would like to present a small form for the user to input two parameters "Start Date" and "End Date". Thanks to another Stack Overflow user ("Kevin Ross"), I learned how to embed the form control directly in the query that is used by the report I would like to display.
SELECT q1.CasesAssigned, q2.WarningsIssued
FROM
(SELECT COUNT(*) AS CasesAssigned
FROM vwCaseDetail
WHERE DateAssigned Between [Forms]![frmReporting]![txtStartDate]
AND [Fo开发者_运维问答rms]![frmReporting]![txtEndDate]) as q1,
(SELECT COUNT(*) AS WarningsIssued
FROM vwWarningDetail
WHERE DateIssued Between [Forms]![frmReporting]![txtStartDate]
AND [Forms]![frmReporting]![txtEndDate]) as q2
I have tried two different ways to open the report and pass the users input:
After the user enters parameters I call
DoCmd.OpenReport "myReport", acViewPreview
. The problem here is that the reports opens and close so fast I never even see it. Ideally I would like to close the input collection form and then open the report.Inside the
Report_Open
event I have code that opens the form that collect the users input. The input collection form opens, however I still get prompted by the report to enter in the two parameters. The report does not seem to be gathering the parameters from the input collection form.
Any suggestions on the proper way to pass data collected on a form to a report? Thank you.
Well,
The problem should be the logic of what your wantig. Why do you want a report calling a form? Why not a form in wich you fulfill the parameters then call the report?
You can perform your requisites in this way:
Create a form containing the fields corresponding to your desired parameters (Eg two textboxes called Param1 and Param2, in a form called Form1)
Create a query that retrieves the data for your report, referencing, in the conditions field, the parameters in the form (In the example,
[Forms]![Form1]![Param1]
and[Forms]![Form1]![Param2]
). Also, right clik on a empty space of query builder and select "parameters". Inform all the parameters (with the entire strings[Forms]![Form1]![Param1]
and[Forms]![Form1]![Param2]
) with the correct data type. Let's call this query Query1Create a report based on Query1. Lets call this report as Report1
Back to Form1, create a button (use the Wizard, its faster) for calling Report1.
Execute the Form1, in runtime fill the textboxes with the desired parameters then click the button. Make sure that you have data in your tables wich corresponds the Query.
In the other parts of your application, instead you call Report1 directly, call the Form1 that will manage Report1 querying and showing.
精彩评论