Results 1 to 4 of 4
  1. #1
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131

    converting number into words in query

    Hi Buddy !I am using code
    Code:
    Option Compare DatabaseOption ExplicitFunction ConvertCurrencyToEnglish(ByVal MyNumber)         Dim Temp         Dim Rupees, Paisas         Dim DecimalPlace, Count         ReDim Place(9) As String         Place(2) = " Thousand "         Place(3) = " Million "         Place(4) = " Billion "         Place(5) = " Trillion "         ' Convert MyNumber to a string, trimming extra spaces.         MyNumber = Trim(Str(MyNumber))         ' Find decimal place.         DecimalPlace = InStr(MyNumber, ".")         ' If we find decimal place...         If DecimalPlace > 0 Then            ' Convert Paisas            Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)            Paisas = ConvertTens(Temp)            ' Strip off Paisas from remainder to convert.            MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))         End If         Count = 1         Do While MyNumber  ""            ' Convert last 3 digits of MyNumber to English Rupees.            Temp = ConvertHundreds(Right(MyNumber, 3))            If Temp  "" Then Rupees = Temp & Place(Count) & Rupees            If Len(MyNumber) > 3 Then               ' Remove last 3 converted digits from MyNumber.               MyNumber = Left(MyNumber, Len(MyNumber) - 3)            Else               MyNumber = ""            End If            Count = Count + 1         Loop         ' Clean up Rupees.         Select Case Rupees            Case ""               Rupees = "No Rupees"            Case "One"               Rupees = "One Rupee"            Case Else               Rupees = Rupees & " Rupees"         End Select         ' Clean up Paisas.         Select Case Paisas            Case ""               Paisas = " And No Paisas"            Case "One"               Paisas = " And One Paisa"            Case Else               Paisas = " And " & Paisas & " Paisas"         End Select         ConvertCurrencyToEnglish = Rupees & Paisas      End Function      Private Function ConvertHundreds(ByVal MyNumber)         Dim Result As String         ' Exit if there is nothing to convert.         If Val(MyNumber) = 0 Then Exit Function         ' Append leading zeros to number.         MyNumber = Right("000" & MyNumber, 3)         ' Do we have a hundreds place digit to convert?         If Left(MyNumber, 1)  "0" Then            Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "         End If         ' Do we have a tens place digit to convert?         If Mid(MyNumber, 2, 1)  "0" Then            Result = Result & ConvertTens(Mid(MyNumber, 2))         Else            ' If not, then convert the ones place digit.            Result = Result & ConvertDigit(Mid(MyNumber, 3))         End If         ConvertHundreds = Trim(Result)      End Function      Private Function ConvertTens(ByVal MyTens)         Dim Result As String         ' Is value between 10 and 19?         If Val(Left(MyTens, 1)) = 1 Then            Select Case Val(MyTens)               Case 10: Result = "Ten"               Case 11: Result = "Eleven"               Case 12: Result = "Twelve"               Case 13: Result = "Thirteen"               Case 14: Result = "Fourteen"               Case 15: Result = "Fifteen"               Case 16: Result = "Sixteen"               Case 17: Result = "Seventeen"               Case 18: Result = "Eighteen"               Case 19: Result = "Nineteen"               Case Else            End Select         Else            ' .. otherwise it's between 20 and 99.            Select Case Val(Left(MyTens, 1))               Case 2: Result = "Twenty "               Case 3: Result = "Thirty "               Case 4: Result = "Forty "               Case 5: Result = "Fifty "               Case 6: Result = "Sixty "               Case 7: Result = "Seventy "               Case 8: Result = "Eighty "               Case 9: Result = "Ninety "               Case Else            End Select            ' Convert ones place digit.            Result = Result & ConvertDigit(Right(MyTens, 1))         End If         ConvertTens = Result      End Function      Private Function ConvertDigit(ByVal MyDigit)         Select Case Val(MyDigit)            Case 1: ConvertDigit = "One"            Case 2: ConvertDigit = "Two"            Case 3: ConvertDigit = "Three"            Case 4: ConvertDigit = "Four"            Case 5: ConvertDigit = "Five"            Case 6: ConvertDigit = "Six"            Case 7: ConvertDigit = "Seven"            Case 8: ConvertDigit = "Eight"            Case 9: ConvertDigit = "Nine"            Case Else: ConvertDigit = ""         End Select      End Function
    .to convert number into words. but this function can't not be used in query to convert number into words.what should i have to do with this code for using it in query?Thank You !

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Whatever you did in posting code caused formatting to corrupt to the point of non-readability.

    Why can't it be used in query?

    Possibly call the function from a textbox on report.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131
    thanks buddy to reply. My problem solved.

  4. #4
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131


    Option Compare Database
    Option Explicit
    Function ConvertCurrencyToEnglish(ByVal MyNumber)
    Dim Temp
    Dim Rupees, Paisas
    Dim DecimalPlace, Count


    ReDim Place(9) As String
    Place(2) = " Thousand "
    Place(3) = " Million "
    Place(4) = " Billion "
    Place(5) = " Trillion "


    ' Convert MyNumber to a string, trimming extra spaces.
    MyNumber = Trim(Str(MyNumber))


    ' Find decimal place.
    DecimalPlace = InStr(MyNumber, ".")


    ' If we find decimal place...
    If DecimalPlace > 0 Then
    ' Convert Paisas
    Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
    Paisas = ConvertTens(Temp)


    ' Strip off Paisas from remainder to convert.
    MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If


    Count = 1
    Do While MyNumber <> ""
    ' Convert last 3 digits of MyNumber to English Rupees.
    Temp = ConvertHundreds(Right(MyNumber, 3))
    If Temp <> "" Then Rupees = Temp & Place(Count) & Rupees
    If Len(MyNumber) > 3 Then
    ' Remove last 3 converted digits from MyNumber.
    MyNumber = Left(MyNumber, Len(MyNumber) - 3)
    Else
    MyNumber = ""
    End If
    Count = Count + 1
    Loop


    ' Clean up Rupees.
    Select Case Rupees
    Case ""
    Rupees = "No Rupees"
    Case "One"
    Rupees = "One Rupee"
    Case Else
    Rupees = Rupees & " Rupees"
    End Select


    ' Clean up Paisas.
    Select Case Paisas
    Case ""
    Paisas = " And No Paisas"
    Case "One"
    Paisas = " And One Paisa"
    Case Else
    Paisas = " And " & Paisas & " Paisas"
    End Select


    ConvertCurrencyToEnglish = Rupees & Paisas
    End Function


    Private Function ConvertHundreds(ByVal MyNumber)
    Dim Result As String


    ' Exit if there is nothing to convert.
    If Val(MyNumber) = 0 Then Exit Function


    ' Append leading zeros to number.
    MyNumber = Right("000" & MyNumber, 3)


    ' Do we have a hundreds place digit to convert?
    If Left(MyNumber, 1) <> "0" Then
    Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "
    End If


    ' Do we have a tens place digit to convert?
    If Mid(MyNumber, 2, 1) <> "0" Then
    Result = Result & ConvertTens(Mid(MyNumber, 2))
    Else
    ' If not, then convert the ones place digit.
    Result = Result & ConvertDigit(Mid(MyNumber, 3))
    End If


    ConvertHundreds = Trim(Result)
    End Function


    Private Function ConvertTens(ByVal MyTens)
    Dim Result As String


    ' Is value between 10 and 19?
    If Val(Left(MyTens, 1)) = 1 Then
    Select Case Val(MyTens)
    Case 10: Result = "Ten"
    Case 11: Result = "Eleven"
    Case 12: Result = "Twelve"
    Case 13: Result = "Thirteen"
    Case 14: Result = "Fourteen"
    Case 15: Result = "Fifteen"
    Case 16: Result = "Sixteen"
    Case 17: Result = "Seventeen"
    Case 18: Result = "Eighteen"
    Case 19: Result = "Nineteen"
    Case Else
    End Select
    Else
    ' .. otherwise it's between 20 and 99.
    Select Case Val(Left(MyTens, 1))
    Case 2: Result = "Twenty "
    Case 3: Result = "Thirty "
    Case 4: Result = "Forty "
    Case 5: Result = "Fifty "
    Case 6: Result = "Sixty "
    Case 7: Result = "Seventy "
    Case 8: Result = "Eighty "
    Case 9: Result = "Ninety "
    Case Else
    End Select


    ' Convert ones place digit.
    Result = Result & ConvertDigit(Right(MyTens, 1))
    End If


    ConvertTens = Result
    End Function


    Private Function ConvertDigit(ByVal MyDigit)
    Select Case Val(MyDigit)
    Case 1: ConvertDigit = "One"
    Case 2: ConvertDigit = "Two"
    Case 3: ConvertDigit = "Three"
    Case 4: ConvertDigit = "Four"
    Case 5: ConvertDigit = "Five"
    Case 6: ConvertDigit = "Six"
    Case 7: ConvertDigit = "Seven"
    Case 8: ConvertDigit = "Eight"
    Case 9: ConvertDigit = "Nine"
    Case Else: ConvertDigit = ""
    End Select
    End Function



    I have again posted my code.
    I am from Nepal. So I want to do little modification on this code.
    Our Currency grouping is little difference from English currency grouping.
    ex. English currency Grouping 999,999,999,999,999
    Nepali Currency grouping 99,99,99,99,99,99,999 (Ninety Nine Nill Ninety Nine Kharab Ninety Nine Arab Ninety Nine Lakh Ninety Nine Thousand Nine Hundred and Ninety Nine)
    where should i have to edit in my code.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. converting number into words
    By joshynaresh in forum Forms
    Replies: 16
    Last Post: 02-28-2014, 12:29 AM
  2. Converting a Number to Decimal
    By lwilt in forum Access
    Replies: 5
    Last Post: 10-11-2013, 05:02 PM
  3. Converting lookup text field to number for primary
    By Ruegen in forum Database Design
    Replies: 4
    Last Post: 09-11-2013, 08:23 PM
  4. Converting text to number type
    By togo in forum Access
    Replies: 12
    Last Post: 09-18-2012, 12:59 PM
  5. Converting negative number to positive using QBE??
    By shabbaranks in forum Queries
    Replies: 5
    Last Post: 03-23-2012, 08:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums