By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,072 Members | 1,168 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,072 IT Pros & Developers. It's quick & easy.

Why will Month() work, but MonthName() won't work in my textbox?

Seth Schrock
Expert 2.5K+
P: 2,951
I've got a textbox on a report that I'm using to pull the month and year from two textboxes on a form. The following code works in the data source of the textbox:
Expand|Select|Wrap|Line Numbers
  1. ="Billing Period: " 
  2. & Month([Forms]![frmCustomer]![txtStartDate]) 
  3. & " " 
  4. & Year([Forms]![frmCustomer]![txtStartDate]) 
  5. & " - " 
  6. & Month([Forms]![frmCustomer]![txtEndDate]) 
  7. & " " 
  8. & Year([Forms]![frmCustomer]![txtEndDate])
However, I would like to make it so that I get the name of the month instead of the number. So I tried the following:

Expand|Select|Wrap|Line Numbers
  1. ="Billing Period: " 
  2. & MonthName([Forms]![frmCustomer]![txtStartDate]) 
  3. & " " 
  4. & Year([Forms]![frmCustomer]![txtStartDate]) 
  5. & " - " 
  6. & MonthName([Forms]![frmCustomer]![txtEndDate]) 
  7. & " " 
  8. & Year([Forms]![frmCustomer]![txtEndDate])
When I preview the report, however, it returns #Func!. Is the MonthName() function not available in this situation? I don't get any syntax errors while in design view of the report. I even tried adding the ,False to the MonthName() function in case it wanted me to explicitly declare the default, but that didn't change anything.
Nov 4 '11 #1

✓ answered by ADezii

The MonthName() Function does not accept a Date as an Argument, but a Numeric Value between 1 and 12, as in:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print MonthName(1)  'returns January
  2. Debug.Print MonthName(10) 'returns October
  3. Debug.Print MonthName(4)  'returns April
  4. Debug.Print MonthName(8)  'returns August
  5. Debug.Print MonthName(6)  'returns June
  6.  
What will work is:
Expand|Select|Wrap|Line Numbers
  1. 'Returns November
  2. Debug.Print MonthName(Month(#11/5/2011#))
  3.  

Share this Question
Share on Google+
2 Replies


ADezii
Expert 5K+
P: 8,679
The MonthName() Function does not accept a Date as an Argument, but a Numeric Value between 1 and 12, as in:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print MonthName(1)  'returns January
  2. Debug.Print MonthName(10) 'returns October
  3. Debug.Print MonthName(4)  'returns April
  4. Debug.Print MonthName(8)  'returns August
  5. Debug.Print MonthName(6)  'returns June
  6.  
What will work is:
Expand|Select|Wrap|Line Numbers
  1. 'Returns November
  2. Debug.Print MonthName(Month(#11/5/2011#))
  3.  
Nov 4 '11 #2

Seth Schrock
Expert 2.5K+
P: 2,951
Okay, that makes sense. Thanks.
Nov 4 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.