Convert Integer to Month.

M

Morris.C

This should be easy, but I just can't figure it out!!
I have a column (field) set as a Number/Integer.
I would like to convert this to a short month value.
eg 1 = Jan
2 = Feb
etc.

I thought it would be as easy as putting a format of 'mmm' in the
textbox's properties. But no...All I get is Jan (or Dec every now and
again)!!!

I then created another textbox and used the MonthName method.
ie. Me!Textbox2 = MonthName(Me!Textbox1).
Problem is I use the forms OnLoad event and it only does it for the first
record. The textbox won't change.
I then thought I could associate this little bit of code with the
Textbox1 (it contains the number), using its OnChange event. But Textbox2
still shows either Jan or Dec!

Any help would be greatly appreciated.

Thanks,
 
R

Rob Parker

I don't understand why you need any code on any event for this. If you
simply set the Control Source for TextBox2 to:

=MonthName([YourNumberFieldName])

it will display the corresponding month name (in long format) for the field
in each record. To get it to display in the short format you've shown, use:

=MonthName([YourNumberFieldName],1)

You might want to wrap this in an iif or Nz statement to catch invalid or
missing data in your number field, to prevent #error being shown.

HTH,

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top