Results 1 to 5 of 5

Thread: How to Convert MonthName to Value(Microsoft access 2003)

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    How to Convert MonthName to Value(Microsoft access 2003)

    Hi All,

    How to Convert MonthName Like September, October to value for enabling sorting. I used Format$(Exp,"mm") but i can't sort the record .

    Thanks you


    PS: Microsoft access 2003
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: How to Convert MonthName to Value(Microsoft access 2003)

    Not sure what you mean. Do you want the month number?
    Tengo mas preguntas que contestas

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: How to Convert MonthName to Value(Microsoft access 2003)

    Use this:
    Month(CDate("1 " & strMonth & " 2000"))

    Or even shorter:
    Month(CDate("1 " & strMonth))

    where strMonth is the name of month such as September, October.

    Note that MonthName() is a VB built-in function that convert a number from 1 to 12 to the name of month:
    MonthName(month[, abbreviate])

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to Convert MonthName to Value(Microsoft access 2003)

    Try this
    vb Code:
    1. Private Function GetMonthNumber(pstrMonthName As String) As Integer
    2. Dim i As Long
    3. For i = 1 To 12
    4.   If pstrMonthName = MonthName(i) Then
    5.      GetMonthNumber = i
    6.      Exit Function
    7.   End If
    8. Next
    9. End Function
    10.  
    11. Private Sub Command1_Click()
    12. Dim intMonth As Integer
    13. intMonth = GetMonthNumber("October")
    14. End Sub

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: How to Convert MonthName to Value(Microsoft access 2003)

    @Hack, why you have to create a UDF while you can use a simple thing like this to return the Month number:

    Month(CDate("1 " & strMonth))

    And your Private function cannot be used in a query.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width