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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #1

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

    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:
    Code:
    ="Billing Period: " 
    & Month([Forms]![frmCustomer]![txtStartDate]) 
    & " " 
    & Year([Forms]![frmCustomer]![txtStartDate]) 
    & " - " 
    & Month([Forms]![frmCustomer]![txtEndDate]) 
    & " " 
    & 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:

    Code:
    ="Billing Period: " 
    & MonthName([Forms]![frmCustomer]![txtStartDate]) 
    & " " 
    & Year([Forms]![frmCustomer]![txtStartDate]) 
    & " - " 
    & MonthName([Forms]![frmCustomer]![txtEndDate]) 
    & " " 
    & 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.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

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

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #3
      Okay, that makes sense. Thanks.

      Comment

      Working...