How do I select the year for a report?

  • Thread starter Thread starter ZBC
  • Start date Start date
Z

ZBC

I want to print reports based on a calendar year ... my tables (query)
covers multiple years.
If for example, I want the report to be for 1998 then I want to print
"Report for Year 1998" on the first page of my report and the report
would just cover the year 2002.
I plan to base the report on a query.
I would like to use a form for user entry to select the year for the report.
What is the best way to do this?
 
ZBC said:
I want to print reports based on a calendar year ... my tables (query)
covers multiple years.
If for example, I want the report to be for 1998 then I want to print
"Report for Year 1998" on the first page of my report and the report
would just cover the year 2002.
I plan to base the report on a query.
I would like to use a form for user entry to select the year for the report.
What is the best way to do this?


Use a text box on the form for the users to enter the year
the report should cover. Then use a command button on the
same form so the users can run the report. In the button's
Click event, use code like:

Dim stDoc As String
Dim stWhere As String
stDoc = "nameofreport"
stWhere = "theyesrfield = " & thetextbox
DoCmd.OpenReport stDoc,acViewPreview, , stWhere
 
Thanks for your help ...
How do I get the 'year incorportated at the top of the report?
Sorry ... new at this ... obviously
I was thinking about placing the year in a pseudo-constants table where
I am storing the company name, tel, etc.
How would this change the code?
Thanks ...
Bob
 
Add an unbound text box to your report and set the control
source to:

="Report for year " & [Forms]![YourForm]![YearFieldName]
 
ZBC said:
Will this work if my records contain a 'date' field rather than just a year?


No, you have to modify it a little:

stWhere = "Year(thedatefield) = " & thetextbox
 
Thanks!
Is there an equivalent to this for a query (where criteria) so I can
easily review the selection?
 
ZBC said:
Thanks!
Is there an equivalent to this for a query (where criteria) so I can
easily review the selection?

In a query you would use a calculated field for
Year(thedatefield)
with a criteria
Forms!theform.thetextbox

Or, in SQL, just use
Year(thedatefield) = Forms!theform.thetextbox
in the Where clause
 
Marshall,
You are someone who really reads the questions! I can always count on
your answers!
I THANK YOU!
Bob
 
ZBC said:
Marshall,
You are someone who really reads the questions! I can always count on
your answers!
I THANK YOU!


You're welcome, Bob. Nice of you to say so.
 
Back
Top