View Full Version : Converting numbers to words in MS Access 2003 report


Uday Nanjappa
07-04-2008, 04:16 AM
Hi,

Anybody please help me out on how to display numbers/currency into words in reports. I use ACC 2003. I want full details please.

Uday

Rich
07-04-2008, 10:15 AM
Function ConvertCurrencyToEnglish(ByVal MyNumber)
Dim Temp
Dim Pounds, Pence
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)
Pence = 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 sterlng
Temp = ConvertHundreds(right(MyNumber, 3))
If Temp <> "" Then Pounds = Temp & Place(count) & Pounds
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 dollars.
Select Case Pounds
Case ""
Pounds = "No Pounds"
Case "One"
Pounds = "One Pound"
Case Else
Pounds = Pounds & " Pounds "
End Select

' Clean up cents.
Select Case Pence
Case ""
Pence = " Only"
Case "One"
Pence = " And One Pence"
Case Else
Pence = " And " & Pence & " Pence"
End Select

ConvertCurrencyToEnglish = Pounds & Pence
End Function

RuralGuy
07-04-2008, 10:28 AM
And another reference:
http://www.mvps.org/access/modules/mdl0001.htm

Uday Nanjappa
07-13-2008, 12:33 AM
Sir,

I used the above code in my report and I am getting an #Name? error mesage in the text box. Please let me know what shall I do to rectify this.

Thank you,

Uday

Uday Nanjappa
07-13-2008, 12:39 AM
Hi,

Anybody please help me out on how to display numbers/currency into words in reports. I use ACC 2003. I want full details please.

Uday

I have received the code by Rich, but I dont know how to go about further. What function should I enter in the text box.

Uday

khawar
07-13-2008, 02:08 AM
Paste the code in a module and in the control source of the control in which you want to show words write:
=ConvertCurrencyToEnglish(Your Field name)

Uday Nanjappa
07-14-2008, 07:35 AM
Paste the code in a module and in the control source of the control in which you want to show words write:
=ConvertCurrencyToEnglish(Your Field name)
Dear Mr. Khawar,

It worked.

Thank you very much, Sir.

Uday