Hi,
I would like to make it very easy for users to control the date range of a
report. Is there a way I can create a simple form or text boxes in my report
for entry of the date range by the user? For example "StartDate" and
"EndDate" textboxes in my report. I want to avoid having users enter date
ranges in the actual query.
Alternate solutions also appreciated.
Thanks,
Diana
1) If you are using a query as record source for the report, an easy
method is to have the query prompt for the date range.
On the Criteria line of the date field in the query, write:
Between [Start Date] and [End Date]
If you also wish to show the entered date range in the report, add an
unbound control to the report header.
Set it's Control Source to something like:
="For sales between " & [Start Date] & " and " [End Date]
Note... the text inside the brackets must be identical to the
bracketed text in the query.
2) A better method would be to use a form to enter the date range in.
Create an unbound form. Add 2 Text Controls.
Name one StartDate and the 2nd EndDate.
Add a command button.
Code the button's click event:
Me.Visible = False
Name this form 'ParamForm'.
In the query that is the record source for the report, in it's Date
field's criteria line, write:
Between forms!ParamForm!StartDate AND forms!ParamForm!EndDate
Next, code the main report's Open event:
DoCmd.OpenForm "ParamForm", , , , , acDialog
Code the main report's Close event:
DoCmd.Close acForm, "ParamForm"
When ready to run the report, open the report. The form will display
and wait for the entry of the dates. Click the command button and the
report will run without need for any further parameter entries. When
the report closes, it will close the form.
If you wish to display the parameters in the report, set the control
source of the unbound control to:
= For sales between " & forms!ParamForm!StartDate & " and " &
forms!ParamForm!EndDate