Using Year Value from date()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I currently have a combo box (cboPeriodYears) that has a list of values
For example

2002-2003
2003-2004
2004-2005
etc

When the form loads, I want the current combo box value to be populated with
the value YYYY-YYYY(+1) based on criteria.

For example; If the date is between 1/9/2004 and 31/8/2005, I want the
cboPeriodYears combo box to be populated with 2003-2004.

And again, if the the date is between 1/9/2005 and 31/8/2006, I want the
cboPeriodYears combo box to be populated 2004-2005.

I am sure I could probably use the format function of the date() somehow.
Any assistance would be greatfully received.
 
Hi,

I currently have a combo box (cboPeriodYears) that has a list of values
For example

2002-2003
2003-2004
2004-2005
etc

When the form loads, I want the current combo box value to be populated with
the value YYYY-YYYY(+1) based on criteria.

For example; If the date is between 1/9/2004 and 31/8/2005, I want the
cboPeriodYears combo box to be populated with 2003-2004.

You can use the builtin date funtions to do this:

Me!cboFiscalYear = Year(DateAdd("m", -8, Date()) & "-" &
Year(DateAdd("m", 4, Date())

John W. Vinson[MVP]
 
Hi Dylan,

This should get you started:

IIF(Month(TheDate)<9,
CStr(Year(TheDate) - 2) & "-" & Cstr(Year(TheDate) - 1),
CStr(Year(TheDate) - 1) & "-" & CStr(Year(TheDate)))
 
Mr Vinson,

Thanks for your assistance. Your code looks extremely eloquent. I have
inserted the code and get a erro 13 type mismatch.

From searching this may have something to do with ADO and DAO in conflict.
I believe I have used both in my coding throughout the entire project.

Any further help would be great.
 
Mr Nurick,

Thanks for your code. It appears to work fine. Is there a way I can test it
without changing the system date on my computer?
 
Please ignore my last post. All is great. Thanks very much.
I even learnt about the CStr and IIF functions in the process. Excellent
(and simple) code. Once I learnt what the function were, decifering your
code was easy. Really no need to test (even though I still did by chnaging
the system date).

My final code read as below.

Me.cboPeriodYears.Value = IIf(month(Date) < 9, CStr(year(Date) - 2) & "-" &
CStr(year(Date) - 1), CStr(year(Date) - 1) & "-" & CStr(year(Date)))

Thanks again to both John's for your help.
 
Back
Top