Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to show numbers in text format... 1

Status
Not open for further replies.

PaulChilds

Technical User
May 21, 2002
195
Bit of an odd one this...

I have a table which records client information. From this I have a query which is used to create a report.

The report is for a bank mandate and has to show a payment amount in figures and text. At the minute the table has a field called 'Payment' (which is set as a currency) in which you would enter '150'(eg) and a text field called 'Payment (in words)' - in which you then enter 'One Hundred and Fifty'.

Is there any way that it can be set so that the database recognises '150' and puts the corresponding word/s in the next column?

If not, never mind - if so, it would save the users a lot of time when they are entering in lots of data.

Cheers.

Paul C
 
The below code will spell out dollar amounts liek on checks.......you can probably modify the output some to make it work......

''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function SpellDollar(dblValue As Double) As String

' Usage - To test it, open the debug window (ctrl+G) and type: ?SpellDollar(any number you want), and hit enter

Dim centspot As Integer, dollarlen As Integer
Dim dollars As Double, Cents As Integer
Dim Hundreds As Integer, Thousands As Integer
Dim Millions As Integer, Billions As Integer
Dim centtext As String, huntext As String, thoutext As String
Dim milltext As String, billtext As String, temptext As String

If dblValue < 0.01 Then
temptext = &quot;Zero&quot;
Else
centspot = InStr(dblValue, &quot;.&quot;)
If centspot > 0 Then
Cents = Right(dblValue, 2)
dollars = Left(dblValue, centspot - 1)
Else
Cents = 0
dollars = dblValue
End If

dollarlen = Len(CStr(dollars))

If dollarlen > 0 Then
Select Case dollars
Case 1 To 999
Select Case dollars
Case 1 To 9
Hundreds = Right(dollars, 1)
Case 10 To 99
Hundreds = Right(dollars, 2)
Case 100 To 999
Hundreds = Right(dollars, 3)
End Select
Case 1000 To 999999
Hundreds = Right(dollars, 3)
Select Case dollars
Case 1000 To 9999
Thousands = Left(dollars, 1)
Case 10000 To 99999
Thousands = Left(dollars, 2)
Case 100000 To 999999
Thousands = Left(dollars, 3)
End Select
Case 1000000 To 999999999
Hundreds = Right(dollars, 3)
Thousands = Mid(dollars, (dollarlen - 5), 3)
Select Case dollars
Case 1000000 To 9999999
Millions = Left(dollars, 1)
Case 10000000 To 99999999
Millions = Left(dollars, 2)
Case 100000000 To 999999999
Millions = Left(dollars, 3)
End Select
Case 1000000000 To 999999999999#
Hundreds = Right(dollars, 3)
Thousands = Mid(dollars, (dollarlen - 5), 3)
Millions = Mid(dollars, (dollarlen - 8), 3)
Select Case dollars
Case 1000000000 To 9999999999#
Billions = Left(dollars, 1)
Case 10000000000# To 99999999999#
Billions = Left(dollars, 2)
Case 100000000000# To 999999999999#
Billions = Left(dollars, 3)
End Select
End Select
End If

If Hundreds > 0 Then huntext = GetDollarString(&quot;hundreds&quot;, Hundreds)
If Thousands > 0 Then thoutext = GetDollarString(&quot;thousands&quot;, Thousands)
If Millions > 0 Then milltext = GetDollarString(&quot;millions&quot;, Millions)
If Billions > 0 Then billtext = GetDollarString(&quot;billions&quot;, Billions)

If billtext = &quot;&quot; Then
If milltext = &quot;&quot; Then
If thoutext = &quot;&quot; Then
If huntext = &quot;&quot; Then
temptext = centtext
Else
temptext = huntext & &quot; Dollars and &quot; & Cents & &quot;/100&quot;
End If
Else
temptext = thoutext & &quot; &quot; & huntext & &quot; Dollars and &quot; & Cents & &quot;/100&quot;
End If
Else
temptext = milltext & &quot; &quot; & thoutext & &quot; &quot; & huntext & &quot; Dollars and &quot; & Cents & &quot;/100&quot;
End If
Else
temptext = billtext & &quot; &quot; & milltext & &quot; &quot; & thoutext & &quot; &quot; & huntext & &quot; Dollars and &quot; & Cents & &quot;/100&quot;
End If
End If

If Right(temptext, 1) = &quot;d&quot; Then temptext = Left(temptext, Len(temptext) - 4)
SpellDollar = Trim(temptext)
End Function

Function GetDollarString(strPart As String, intPart As Integer) As String
Dim strDollars As String

If intPart > 99 Then
Select Case Mid(intPart, 1, 1)
Case 1: strDollars = &quot;One Hundred&quot;
Case 2: strDollars = &quot;Two Hundred&quot;
Case 3: strDollars = &quot;Three Hundred&quot;
Case 4: strDollars = &quot;Four Hundred&quot;
Case 5: strDollars = &quot;Five Hundred&quot;
Case 6: strDollars = &quot;Six Hundred&quot;
Case 7: strDollars = &quot;Seven Hundred&quot;
Case 8: strDollars = &quot;Eight Hundred&quot;
Case 9: strDollars = &quot;Nine Hundred&quot;
End Select
End If

Select Case Right(intPart, 2)
Case 1: strDollars = strDollars & &quot; One&quot;
Case 2: strDollars = strDollars & &quot; Two&quot;
Case 3: strDollars = strDollars & &quot; Three&quot;
Case 4: strDollars = strDollars & &quot; Four&quot;
Case 5: strDollars = strDollars & &quot; Five&quot;
Case 6: strDollars = strDollars & &quot; Six&quot;
Case 7: strDollars = strDollars & &quot; Seven&quot;
Case 8: strDollars = strDollars & &quot; Eight&quot;
Case 9: strDollars = strDollars & &quot; Nine&quot;
Case 10: strDollars = strDollars & &quot; Ten&quot;
Case 11: strDollars = strDollars & &quot; Eleven&quot;
Case 12: strDollars = strDollars & &quot; Twelve&quot;
Case 13: strDollars = strDollars & &quot; Thirteen&quot;
Case 14: strDollars = strDollars & &quot; Fourteen&quot;
Case 15: strDollars = strDollars & &quot; Fifteen&quot;
Case 16: strDollars = strDollars & &quot; Sixteen&quot;
Case 17: strDollars = strDollars & &quot; Seventeen&quot;
Case 18: strDollars = strDollars & &quot; Eighteen&quot;
Case 19: strDollars = strDollars & &quot; Nineteen&quot;
Case 20: strDollars = strDollars & &quot; Twenty&quot;
Case 21: strDollars = strDollars & &quot; Twenty One&quot;
Case 22: strDollars = strDollars & &quot; Twenty Two&quot;
Case 23: strDollars = strDollars & &quot; Twenty Three&quot;
Case 24: strDollars = strDollars & &quot; Twenty Four&quot;
Case 25: strDollars = strDollars & &quot; Twenty Five&quot;
Case 26: strDollars = strDollars & &quot; Twenty Six&quot;
Case 27: strDollars = strDollars & &quot; Twenty Seven&quot;
Case 28: strDollars = strDollars & &quot; Twenty Eight&quot;
Case 29: strDollars = strDollars & &quot; Twenty Nine&quot;
Case 30: strDollars = strDollars & &quot; Thirty&quot;
Case 31: strDollars = strDollars & &quot; Thirty One&quot;
Case 32: strDollars = strDollars & &quot; Thirty Two&quot;
Case 33: strDollars = strDollars & &quot; Thirty Three&quot;
Case 34: strDollars = strDollars & &quot; Thirty Four&quot;
Case 35: strDollars = strDollars & &quot; Thirty Five&quot;
Case 36: strDollars = strDollars & &quot; Thirty Six&quot;
Case 37: strDollars = strDollars & &quot; Thirty Seven&quot;
Case 38: strDollars = strDollars & &quot; Thirty Eight&quot;
Case 39: strDollars = strDollars & &quot; Thirty Nine&quot;
Case 40: strDollars = strDollars & &quot; Forty&quot;
Case 41: strDollars = strDollars & &quot; Forty One&quot;
Case 42: strDollars = strDollars & &quot; Forty Two&quot;
Case 43: strDollars = strDollars & &quot; Forty Three&quot;
Case 44: strDollars = strDollars & &quot; Forty Four&quot;
Case 45: strDollars = strDollars & &quot; Forty Five&quot;
Case 46: strDollars = strDollars & &quot; Forty Six&quot;
Case 47: strDollars = strDollars & &quot; Forty Seven&quot;
Case 48: strDollars = strDollars & &quot; Forty Eight&quot;
Case 49: strDollars = strDollars & &quot; Forty Nine&quot;
Case 50: strDollars = strDollars & &quot; Fifty&quot;
Case 51: strDollars = strDollars & &quot; Fifty One&quot;
Case 52: strDollars = strDollars & &quot; Fifty Two&quot;
Case 53: strDollars = strDollars & &quot; Fifty Three&quot;
Case 54: strDollars = strDollars & &quot; Fifty Four&quot;
Case 55: strDollars = strDollars & &quot; Fifty Five&quot;
Case 56: strDollars = strDollars & &quot; Fifty Six&quot;
Case 57: strDollars = strDollars & &quot; Fifty Seven&quot;
Case 58: strDollars = strDollars & &quot; Fifty Eight&quot;
Case 59: strDollars = strDollars & &quot; Fifty Nine&quot;
Case 60: strDollars = strDollars & &quot; Sixty&quot;
Case 61: strDollars = strDollars & &quot; Sixty One&quot;
Case 62: strDollars = strDollars & &quot; Sixty Two&quot;
Case 63: strDollars = strDollars & &quot; Sixty Three&quot;
Case 64: strDollars = strDollars & &quot; Sixty Four&quot;
Case 65: strDollars = strDollars & &quot; Sixty Five&quot;
Case 66: strDollars = strDollars & &quot; Sixty Six&quot;
Case 67: strDollars = strDollars & &quot; Sixty Seven&quot;
Case 68: strDollars = strDollars & &quot; Sixty Eight&quot;
Case 69: strDollars = strDollars & &quot; Sixty Nine&quot;
Case 70: strDollars = strDollars & &quot; Seventy&quot;
Case 71: strDollars = strDollars & &quot; Seventy One&quot;
Case 72: strDollars = strDollars & &quot; Seventy Two&quot;
Case 73: strDollars = strDollars & &quot; Seventy Three&quot;
Case 74: strDollars = strDollars & &quot; Seventy Four&quot;
Case 75: strDollars = strDollars & &quot; Seventy Five&quot;
Case 76: strDollars = strDollars & &quot; Seventy Six&quot;
Case 77: strDollars = strDollars & &quot; Seventy Seven&quot;
Case 78: strDollars = strDollars & &quot; Seventy Eight&quot;
Case 79: strDollars = strDollars & &quot; Seventy Nine&quot;
Case 80: strDollars = strDollars & &quot; Eighty&quot;
Case 81: strDollars = strDollars & &quot; Eighty One&quot;
Case 82: strDollars = strDollars & &quot; Eighty Two&quot;
Case 83: strDollars = strDollars & &quot; Eighty Three&quot;
Case 84: strDollars = strDollars & &quot; Eighty Four&quot;
Case 85: strDollars = strDollars & &quot; Eighty Five&quot;
Case 86: strDollars = strDollars & &quot; Eighty Six&quot;
Case 87: strDollars = strDollars & &quot; Eighty Seven&quot;
Case 88: strDollars = strDollars & &quot; Eighty Eight&quot;
Case 89: strDollars = strDollars & &quot; Eighty Nine&quot;
Case 90: strDollars = strDollars & &quot; Ninety&quot;
Case 91: strDollars = strDollars & &quot; Ninety One&quot;
Case 92: strDollars = strDollars & &quot; Ninety Two&quot;
Case 93: strDollars = strDollars & &quot; Ninety Three&quot;
Case 94: strDollars = strDollars & &quot; Ninety Four&quot;
Case 95: strDollars = strDollars & &quot; Ninety Five&quot;
Case 96: strDollars = strDollars & &quot; Ninety Six&quot;
Case 97: strDollars = strDollars & &quot; Ninety Seven&quot;
Case 98: strDollars = strDollars & &quot; Ninety Eight&quot;
Case 99: strDollars = strDollars & &quot; Ninety Nine&quot;
End Select

ConstructString:
Select Case strPart
Case &quot;cents&quot;
GetDollarString = strDollars & &quot;/100&quot;
Case &quot;hundreds&quot;
GetDollarString = strDollars
Case &quot;thousands&quot;
GetDollarString = strDollars & &quot; Thousand&quot;
Case &quot;millions&quot;
GetDollarString = strDollars & &quot; Million&quot;
Case &quot;billions&quot;
GetDollarString = strDollars & &quot; Billion&quot;
End Select
End Function Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
OK...the code should have been copied into a module and saved...any name does not matter.....

The form you are inputing data through (yes I said form....shame on you if the users are/will be inputing data directly into the table...that's a definite no-no) has two fields...one for the numeric number and one for the text number....set the text number field's enabled property to no and the locked property to yes.

Using the afterupdate property of the numeric number field, place the following....

Me![name of text number field] = SpellDollar(Me![name of numeric number field])

That should be it....

If you are still having difficulties...shoot me an email and I will put together a sample database for you...... Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! [thumbsup2]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top