Adding month-end dates to a combobox on the fly

J

James

One of my forms will need to enable the user to choose the
month/day/year, where the day is always the last day of the month. Is
there a way to do this on the fly, or do I need to set up tables with
dates prepopulated?
 
D

Douglas J Steele

If you have a way to select the year and month, the last day of the month
will always be:

DateSerial(YearValue, MonthValue + 1, 0)
 
J

James

And could you recommend a way of generating a list of months and years
on the fly, or should this be a lookup into a table?

Thanks.
 
D

Douglas J Steele

This is probably a case where hard-coding the months into the combo boxes
would be appropriate (unless you have some other need for a table of valid
months). You could hard-code the years as well by using something like the
following in the form's Load event:

Me.cboYears.RowSourceType = "Value List"
Me.cboYears.RowSource = Year(Date()) - 2 & ":" & Year(Date()) - 1 & ";" &
Year(Date()) & ";" & Year(Date()) + 1

or whatever years are appropriate for your case.
 
Top