turning the month into a number using vba

jabjab25

New member
Local time
Today, 19:14
Joined
May 2, 2013
Messages
8
hi there im doing my ict unit 7 edexcel ict exam atm and as one of the tasks we have been asked to generate the testid. the test id consits the year a underscore and then the number of the month so for example if a test happened this year and this month the test id should be 2013_5. i can get the year and the underscore into the code to generate the testid but im not sure how to get the month to change to a number so for example if i select may from a drop down the code needs to take that and generate it into a number. any help would be great
 
Try the DatePart Function.

For example:

DatePart ('yyyy', #15/10/1998#) would return 1998
DatePart ('m', #15/10/2003#) would return 10
DatePart ('d', #15/10/2003#) would return 15

Catalina
 
jabjab25

So you have the months (Jan-Dec) in a combo box. What is the setting of its Row Source property.
 
hey catalina nice idea but in my case i dont see it working on my form i have the following text boxes : TestID, TestMonth, TestComments, Test Year. so the user will input the test year and the test month ie may. the user will then click the test ID button and the code behind the button should then look at the month thats been inputted change it to a number and then generate the testid in the required format
 
hi bob fitz
atm i dont have it set as a combo box just as an ordinary text box so the user would have to input the month themselves but in the exam i would ofcourse change the text box for a combo box would this make a difference in the type of code i would need to use. in my exam model for the validation on the month i have a lookup running which has the drop down where you can select from January-December in my testing work its set as a normal text box. hope that helped
 
Best that you use a combo box. Set its "Row Source Type" property to Value List. Set its "Row Source" property to 1;Jan;2;Feb;2;Mar...... etc. Set its Column Count property to 2. Set its Column Widths property to 0cm;2cm . Set its Limit to list property to True. Set its "Bound Column" property to 1
If you reference the combo box, the value returned will be the number in the first of its columns. So with May selected, "5" will be returned.
 
ill give that a shoot and see what happens thanks for the help
 

Users who are viewing this thread

Back
Top Bottom