MS Access: MonthName Function
This MSAccess tutorial explains how to use the Access MonthName function with syntax and examples.
Description
The Microsoft Access MonthName function returns a string representing the month given a number from 1 to 12.
Syntax
The syntax for the MonthName function in MS Access is:
MonthName ( number, [abbreviate] )
Parameters or Arguments
- number
- A value from 1 to 12, representing the month.
- abbreviate
- Optional. This parameter accepts a boolean value, either TRUE or FALSE. If this parameter is set to TRUE, it means that the month name is abbreviated. If this parameter is set to FALSE, the month name is not abbreviated. If this parameter is omitted, it defaults to FALSE.
Returns
The MonthName function returns a string value.
Applies To
The MonthName function can be used in the following versions of Microsoft Access:
- Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000
Example
Let's look at how to use the MonthName function in MS Access:
MonthName (3) Result: 'March' MonthName (3, TRUE) Result: 'Mar' MonthName (7, FALSE) Result: 'July'
Example in VBA Code
The MonthName function can be used in VBA code in Microsoft Access.
For example:
Dim LValue As String LValue = MonthName (3, TRUE)
In this example, the variable called LValue would now contain the value of 'Mar'.
Example in SQL/Queries
You can also use the MonthName function in a query in Microsoft Access.
For example:
In this query, we have used the MonthName function as follows:
Expr1: MonthName(7,False)
This query will return the full month name for the value 7 and display the results in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.
For example:
MonthValue: MonthName(7,False)
The results would now be displayed in a column called MonthValue.
Advertisements