Is it possible to have query criteria auto-update?

ml8889

Registered User.
Local time
Yesterday, 19:38
Joined
Oct 12, 2012
Messages
19
I have a query that has a Year field. I want the report and form that I generate from this query to only show current year results. I already put 2012 in the criteria area of the field for now. Is it possible for me to write an expression (or other) that will update to 2013 when the new year rolls around? And then 2014, etc. etc.? Or do I have to manually do this at the turn of each year? Please advise. Thanks!
 
If you always only want the current year, then using Year(Date()) in the query will always return the year part of the current date. So on Dec 31, 2012, it returns 2012 and on Jan 1, 2013, it will return 2013. Usually, it is more flexible to use a form to provide criteria for queries. On the form, you can have the control defult to the current year but allow it to be overridden. In the Current event of the form, this line of code will provide a default value:
Code:
Me.txtYear = Year(Date())
Then your query will refer to the control on the form:
Select ...
From ...
Where Year(SomeDateField) = Forms!yourform!txtYear;
 

Users who are viewing this thread

Back
Top Bottom