combo boxes for month, day and year

  • Thread starter Thread starter Han
  • Start date Start date
H

Han

I have a date column in the following format:

8/23/03

I would like three combo boxes for the month, day and year using the
following format:

August 23 2003

The month combo box will be populated with the months (January-December),
the day combo box will contain the days (1-31.. I'm not going to worry about
months with 30 or less days) and the year will contain a 4-digit year
(2003-2010).

After the user has changed the month, day and/or year, the new date will be
saved.

I know this will require a afterupdate routine to extract the values of each
combo box and save the values in date format.

Any comments/suggestions including examples of how to achieve this would be
greatly appreciated.

Thanks,
Han
 
For the month combo box, populate its row source with a two column list:
"1";"January";"2";"February";"3";"March"; etc.

Bind the combo box to the first column, make the first column invisible.

Then when all three combo boxes have been selected, the code that you'll
want to run is this:
CombinedDate = DateSerial(Me.cboYear, Me.cboMonth, Me.cboDay)
 
Ken, thanks for the advice.

One question though. How do you extract the month, day and year from the
date field and set the default in each respective combo box?

Thanks in advance,
Han
 
Ok, getting a little closer.

I added the expression "=Month([LossDate])" to Control Source. It now
displays the correct month, but won't allow me to change the combo box
because "it's bound to an expression."

To be continued...

Ken Snell said:
To extract the month:
Month([DateFieldName])

To extract the day:
Day([DateFieldName])

To extract the year:
Year([DateFieldName])

All of the above functions return an integer number.

I'm not sure I understand what you mean by "set the default in each combo
box"? It's possible to set the "default value" of a control to a value
(either in form's design view or by running code in the form when it's
loading or at any time thereafter); are you wanting to get a date from a
table and use that to set the combo box defaults/initial values?

Give me a bit more info about the source of the date value and what you want
to do, and then we'll find a way to do that for you.

--
Ken Snell
<MS ACCESS MVP>

Han said:
Ken, thanks for the advice.

One question though. How do you extract the month, day and year from the
date field and set the default in each respective combo box?

Thanks in advance,
Han
 
Back
Top