Results 1 to 6 of 6
  1. #1
    dannygan is offline Novice
    Windows XP Access 2000
    Join Date
    May 2009
    Posts
    3

    Amount in word in MS. Access 2000 (VBA)

    Hi Experts,

    I have code which is the result will display e.g amount = 100 then it will covert to word "One Hundred" without the "Only". How am i going to display to "One Hundred Only". Thanks.

    Regards,
    Danny

    Option Compare Database
    'Public crApplication As CRAXDRT.Application
    'Public pbCR As CRAXDRT.Report
    'Public crReport As CRAXDRT.Report
    'Public crReportObject As CRAXDRT.ReportObjects
    'Public crDBFieldDef As CRAXDRT.DatabaseFieldDefinition
    'Public crDBFieldDefs As CRAXDRT.DatabaseFieldDefinitions
    'Public crSortField As CRAXDRT.SortField
    'Public crSortFields As CRAXDRT.SortFields
    'Public crSQL, crFromDate, crToDate As String
    'Public X As CRAXDRT.CRLegendPosition
    Function ConvertCurrencyToEnglish(ByVal MyNumber)
    Dim Temp
    Dim Dollars, Cents
    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 cents
    Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
    Cents = ConvertTens(Temp)
    ' Strip off cents 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 dollars.
    Temp = ConvertHundreds(Right(MyNumber, 3))
    If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
    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




    Select Case Dollars
    Case ""
    Dollars = "" & " ONLY"
    Case "One"
    Dollars = "ONE" & " ONLY"
    Case Else
    Dollars = Dollars & " "
    End Select



    'Clean up cents.
    Select Case Cents
    Case ""
    Cents = ""
    Case "One"
    Cents = "CENT ONE" & " ONLY"
    Case Else
    Cents = " CENTS " & Cents & " ONLY"
    End Select




    ConvertCurrencyToEnglish = Dollars & Cents
    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

  2. #2
    thhui is offline Competent Performer
    Windows XP Access 2002 (version 10.0)
    Join Date
    Feb 2009
    Posts
    235
    Change to this after my trial:

    Code:
    Option Compare Database
    
    'Public crApplication As CRAXDRT.Application
    'Public pbCR As CRAXDRT.Report
    'Public crReport As CRAXDRT.Report
    'Public crReportObject As CRAXDRT.ReportObjects
    'Public crDBFieldDef As CRAXDRT.DatabaseFieldDefinition
    'Public crDBFieldDefs As CRAXDRT.DatabaseFieldDefinitions
    'Public crSortField As CRAXDRT.SortField
    'Public crSortFields As CRAXDRT.SortFields
    'Public crSQL, crFromDate, crToDate As String
    'Public X As CRAXDRT.CRLegendPosition
    
    Function ConvertCurrencyToEnglish(ByVal MyNumber)
    
    Dim Temp
    Dim Dollars, Cents
    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 cents
    Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
    Cents = ConvertTens(Temp)
    ' Strip off cents 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 dollars.
    Temp = ConvertHundreds(Right(MyNumber, 3))
    If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
    
    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
    
    Select Case Dollars
    Case ""
    Dollars = "" & " ONLY"
    Case "One"
    Dollars = "ONE" & " ONLY"
    Case Else
    Dollars = Dollars & " "
    End Select
    
    'Clean up cents.
    Select Case Cents
    Case ""
    Cents = "ONLY"
    Case "One"
    Cents = "CENT ONE" & " ONLY"
    Case Else
    Cents = "CENTS " & Cents & " ONLY"
    End Select
    
    ConvertCurrencyToEnglish = Dollars & Cents
    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

  3. #3
    dannygan is offline Novice
    Windows XP Access 2000
    Join Date
    May 2009
    Posts
    3

    Auto generate amount in word for all row

    Hi thhui,

    Thanks, it is working. Besides that, i have a question which i have a table which have a numberic Amount as below i want it when i click the button, it will auto generate the amount in word in all row by using below convertion. Is it possible to do that?

    A-------------$1030--------
    B-------------$1230--------
    C-------------$1203--------
    D-------------$1902--------


    Thanks again.

    Regards,
    Danny

  4. #4
    thhui is offline Competent Performer
    Windows XP Access 2002 (version 10.0)
    Join Date
    Feb 2009
    Posts
    235
    You can use the function in query, form or report.

    Just for example,

    You put in a query

    select fieldAmount, convertcurrencytoenglish(fieldAmount) as englishAmount from TableA

  5. #5
    dannygan is offline Novice
    Windows XP Access 2000
    Join Date
    May 2009
    Posts
    3
    Hi thhui,


    Thanks a lot for your ideals. You are expert.

    Regards,
    Danny

  6. #6
    thhui is offline Competent Performer
    Windows XP Access 2002 (version 10.0)
    Join Date
    Feb 2009
    Posts
    235
    Glad to see your posting back with success.
    If your issue is resolved, may you use this forum's thread tools feature to mark it solved.

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

Similar Threads

  1. Access 2000 Auto Populated Fields
    By Cylena in forum Access
    Replies: 1
    Last Post: 05-18-2009, 07:50 AM
  2. Access 2000
    By jerald in forum Access
    Replies: 1
    Last Post: 03-15-2009, 04:12 PM
  3. Access 2000 programming startup options
    By nosaj_ccfc in forum Programming
    Replies: 2
    Last Post: 10-17-2008, 02:18 PM
  4. very slow when connect to access 2000
    By pureland in forum Access
    Replies: 0
    Last Post: 10-23-2007, 05:42 AM
  5. Replies: 1
    Last Post: 05-14-2006, 09:01 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