Need your help to advise how to autofill combo box with years (eg 2018, 2017, 2016).
I'd tried Year(Date); Year(Date)-1 ; Year(Date)-2 in Row Source. But this does not work.
Need your help to advise how to autofill combo box with years (eg 2018, 2017, 2016).
I'd tried Year(Date); Year(Date)-1 ; Year(Date)-2 in Row Source. But this does not work.
The easiest way is to use a Value List and just type in those numbers separated by commas as you have done here
The numbers in the combo box are this year, last year and year before last year.
If I type in the numbers, I've to change it every year. In the beginning of next year, I'll have to change it to 2019, 2018 , 2017.
Any solution ?
Look at this demo:
Can change the number of years displayed/select-able:
Code:Case acLBGetRowCount ListYears = 4 ' ListYears = 200 Case acLBGetValue ListYears = intYear - 2 + lngRow ' ListYears = intYear - 100 + lngRow End Select
Ah - you didn't make that clear in your first post
I have a similar situation for a listbox where I list the last 5 years of exams data:
This is automatically updated every year
However to do this I'm using a query to get the exam years in descending order & selecting the top 5
I think you need to do something similar.
Use a table containing dates for the 3 years you want and base a query on that.
I assume you must have such a table or there'd be no point having the combobox!
EDIT - posted before seeing ssanfu's solution - very neat!
Use a query as RowSource (table name may be of any of existing table in application)
Code:SELECT DISTINCT YEAR(DATE())-2 AS YearNo FROM AnyTable UNION SELECT YEAR(DATE())-1 AS YearNo FROM AnyTable UNION SELECT YEAR(DATE()) AS YearNo FROM AnyTable;
Thanks ridders52, ssanfu and ArviLaanemets for your fast response and great help...The problem had been solved.