Sorting report by date range

D

David

I hae a query set up to sort all my data into nice little reports. The only
problem is a month from now I don't want to have to print everything just to
get yesterdays report. I would like a query that says only show the records
for date X through Y, and I would like to use a form to enter the dates, run
the query then show the report for printing.

Thanks
David
 
M

Matt

Add 2 combo boxes to an unbound form (beginning of date range, and end of
date range). Enter the following parameter in the date field of your query.
Between [forms]![yourformname]![comboX] and [forms]![yourformname]![comboY]

When you enter dates into your combo boxes, the query will take the values
entered and restrict the results based on them.
 
F

fredg

I hae a query set up to sort all my data into nice little reports. The only
problem is a month from now I don't want to have to print everything just to
get yesterdays report. I would like a query that says only show the records
for date X through Y, and I would like to use a form to enter the dates, run
the query then show the report for printing.

Thanks
David

Create an unbound form.
Add 2 unbound text controls
Name one control 'StartDate'.
Name the other control 'EndDate'
Set their format property to any valid date format.

Add a Command Button to the form.
Code the button's click event as follows:

(Note: To write the code, in Form Design View select the command
button. Display the button's property sheet.
Click on the Event tab.
On the On Click line, write:

[Event Procedure]

Click on the little button with the 3 dots that appears on that line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those lines, write the following code.)

Me.Visible = False

Close the Code window.

Name this form 'ParamForm'.

In the Query that is the Report's Record Source [DateField] criteria
line write:

Between forms!ParamForm!StartDate and forms!ParamForm!EndDate

Next, code the Report's Open event:
(Using the same method as described above)

DoCmd.OpenForm "ParamForm", , , , , acDialog

Code the report's Close event:

DoCmd.Close acForm, "ParamForm"

When ready to run the report, open the report.
The form will open and wait for the entry of the starting and ending
dates.
Click the command button and then report will run.
When the report closes, it will close the form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top