We help IT Professionals succeed at work.

Convert Date Name to Date Number

jann3891
jann3891 used Ask the Experts™
on
Hello Experts,
I am using Microsoft Access 2003.
I have a form with a drop down list (DateName), User selects the Month from this drop down list... January, February, March.... etc.
I also have a text box (MonthStartDate) on the same form that I want to populate with the first day of the month that the user selects.
So, if the user selects March, the text box will show 03/01/10 - which is current year.

Any ideas??

Thank you in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
use switch

monthnumber=switch(DateName="january",1,DateName="February",2,DateName="March",3,DateName="April",4,DateName="May",5,DateName="june",6,DateName="july",7,DateName="August",8,DateName="September",9,DateName="October",10,DateName="November",11,DateName="December",12)
Owner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
How about modifying the RowSource of the dropdown list so that it contains 2 columns, the month #, and the text of the month.  Set the column width of the month # to zero, then in the after update event of the combo box, do something like:

me.txtMonthStartDate = DateSerial(Year(date), val(me.cboDateName), 1)

Author

Commented:
Perfect !!