How to Convert MonthName to Value(Microsoft access 2003)-VBForums
Results 1 to 5 of 5

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

  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
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,334

    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
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.