Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Access

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 05-27-2009, 05:14 AM
dannygan dannygan is offline Windows XP Access 2000 (version 9.0)
Novice
 
Join Date: May 2009
Posts: 3
dannygan is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 06-04-2009, 05:57 AM
thhui thhui is offline Windows XP Access 2002 (version 10.0)
Competent Performer
 
Join Date: Feb 2009
Posts: 117
thhui is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 06-04-2009, 09:47 PM
dannygan dannygan is offline Windows XP Access 2000 (version 9.0)
Novice
 
Join Date: May 2009
Posts: 3
dannygan is on a distinguished road
Default 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
Reply With Quote
  #4  
Old 06-05-2009, 03:06 AM
thhui thhui is offline Windows XP Access 2002 (version 10.0)
Competent Performer
 
Join Date: Feb 2009
Posts: 117
thhui is on a distinguished road
Default

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
Reply With Quote
  #5  
Old 06-07-2009, 06:58 PM
dannygan dannygan is offline Windows XP Access 2000 (version 9.0)
Novice
 
Join Date: May 2009
Posts: 3
dannygan is on a distinguished road
Default

Hi thhui,


Thanks a lot for your ideals. You are expert.

Regards,
Danny
Reply With Quote
  #6  
Old 06-07-2009, 09:52 PM
thhui thhui is offline Windows XP Access 2002 (version 10.0)
Competent Performer
 
Join Date: Feb 2009
Posts: 117
thhui is on a distinguished road
Default

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.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2000 Auto Populated Fields Cylena Access 1 05-18-2009 05:50 AM
Access 2000 jerald Access 1 03-15-2009 02:12 PM
Access 2000 programming startup options nosaj_ccfc Programming 2 10-17-2008 12:18 PM
very slow when connect to access 2000 pureland Access 0 10-23-2007 03:42 AM
Corruption problem Access 2000 - long, but please read allochthonous Access 1 05-14-2006 07:01 AM


All times are GMT -8. The time now is 02:50 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.