Convert integer to month name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Access 2003: I have a form with an integer field from 0 to 12, representing
the months of the year. I want to include the month in the form header, but
I want it to display the NAME of the month, rather than the number. I've
tried a couple of the formatting and converting functions, but no luck. Any
suggestions?
Thanks!

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/office/com...30caaa2f58e9&dg=microsoft.public.access.forms
 
Try the MonthName() function.

Example:
MonthName(1)
returns January or
MonthName(1, True)
returns Jan
 
Various ways. Here's just one. Each month name in the constant string
must be padded out (with spaces) to 9 characters, exactly.

const MonthNames = "January February March April May June
July August SeptemberOctober November December "
dim n as integer
n = 5 ' or whatever.
s = rtrim$(instr(MonthNames, 9*n-8, 9))
msgbox n & vbcrlf & s

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
Especially if you need the months in other languages! <g>

Another alternative is:

Function GetMonthName(MonthNumber As Integer) As String

GetMonthName = Format(DateSerial(2006, MonthNumber, 1), "mmmm")

End Function
 
Help! This is exactly what I need in a report. The parameter query is looking
for the month integer, and I would like a field on the report that shows the
month name. I have read this string, but am not quite sure what to do with
the MonthName() function. Where do I put it, how do I define the returns, etc.

Thanks!
Marisa
 
In the textbox that you want the month's name displayed, set its Control
Source to

=MonthName([MonthNumberField])

If you need other text in this textbox, you can concatenate it in.

="This is for the month of " & MonthName([MonthNumberField])
 
Back
Top