MonthName misspelling "June"?

nasa09

Registered User.
Local time
Today, 08:45
Joined
Jun 12, 2015
Messages
41
I'm having a strange problem using the MonthName function. I have code that (among other things) checks to see if a directory exists and then creates it if it doesn't already. The thing is, it works correctly for every month except June; for some reason, the MonthName function spells the month "Jun" rather than "June."

A portion of the code is below...does anyone have any idea what might be causing this?

Code:
Dim fullDate As Date
Dim numMon As Integer
Dim nameMon As String
Dim filePath, fileName As String
 
'construct file name and prepare for saving
fullDate = txtBegin.Value
numMon = Month(fullDate)
nameMon = MonthName(numMon)
filePath = "\\corp.confidential.com\userstate\JPowers\Documents\KPI\" & Year(fullDate) & "-" & Format(numMon, "00" & " " & nameMon)
 
'Create parent directory if it does not already exist
If Dir(filePath, vbDirectory) = "" Then
    MkDir filePath
End If
If Dir(filePath & "\RAW", vbDirectory) = "" Then
    MkDir filePath & "\RAW"
End If
 
I can't replicate this problem here. I am using Access 2007. What is your version? Maybe others can report on whether they can cause this problem.

A simple fix would be to write your own MonthName function that does a specific correction for June, like . . .
Code:
Function MyMonthName(iMonth as Integer) As String
   If iMonth = 6 Then
      MyMonthName = "June"
   Else
      MyMonthName = MonthName(iMonth)
   End If
End Function
Then call your custom function in place of VBA.MonthName
Code:
numMon = Month(fullDate)
nameMon = [COLOR="Red"]My[/COLOR]MonthName(numMon)
HTH
 
Thanks, Mark. It's so strange. I'm using Access 2010, but I had the same problem when I used similar code in Excel a couple of days ago. My backup plan was to build my own function like you suggested, but I wanted to run it by you folks first to see if there was an obvious goof on my part. :)
 
silly question, but are sure it definitely isn't june? ...

I would add a break, and single step the code to see what is going on.

alternatively try formatting this way

format(fullDate, "yy-mm mmmm")


?format(Date, "yy-mm mmmm")
15-07 July
 
Rookie and Dave,

No such luck. The changes don't seem to make a difference. This is so strange, but I won't dwell on it, as Mark's suggestion to make my own function works quite well.
 
you haven't got your own "monthname" function in there somewhere have you?
 
Nope, at least not originally. I did create one at Mark's suggestion though.

The strange thing is, the problem is still happening even with the Function that Mark wrote. Even stranger, elsewhere in the sub I use the same method and the same variables to construct the name of the actual file, and that works out just fine; it spells "June" correctly. It's only when the code creates the directory that it leaves off the "e".

It's puzzling.
 
It appears to be this line of code

Code:
Format(numMon, "00" & " " & nameMon)

I tried it on my 2003 version and it did the same, however

Code:
Format(numMon, "00") & " " & nameMon

works as expected.

HTH
 
Gasman,

THANK YOU. That did the trick! I knew it had to be some silly little thing that was easily overlooked.

And thanks to all of you, for all of your suggestions and replies.
 

Users who are viewing this thread

Back
Top Bottom