Number Code

  • Thread starter Thread starter Fred
  • Start date Start date
F

Fred

I am trying to produce payment details on a preprinted
cheque using a report. The value of the cheque is
displayed in the report
and under this I want a separate field(s) with the
individual digits of the number shown in words eg
651,253 to be displayed
as 'Six' 'Five' 'One' 'Two' 'Five' 'Three.
I have the code that displays the value as Six Hundred
and Fifty One etc., but this is not what I want.

Someone replied with the following code:
Fred,

You can write a user defined function to return the individual number as
a text word.

Function Converting(NumIn)
' Convert numbers to their individual word.
Dim strY As String
Dim strString As String
Dim intX As Integer
For intX = 1 To Len(NumIn)
strY = Mid(NumIn, intX, 1)
If strY = "0" Then
strY = "10"
End If
strString = strString & Choose(Val (strY), "One", "Two",
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Zero")

Next intX
Converting = strString
End Function
======
You can call it from a control on a report, or as below, from a query:
TextWords:Converting([NumberField])

Hope this helps

I tried this by creating a module and pasting the code.
When I used Coverter([Field name]) I was taken to the VBA
code.

Please help

Thanks Fred
 
Fred said:
I am trying to produce payment details on a preprinted
cheque using a report. The value of the cheque is
displayed in the report
and under this I want a separate field(s) with the
individual digits of the number shown in words eg
651,253 to be displayed
as 'Six' 'Five' 'One' 'Two' 'Five' 'Three.
I have the code that displays the value as Six Hundred
and Fifty One etc., but this is not what I want.

Someone replied with the following code:
Fred,

You can write a user defined function to return the individual number as
a text word.

Function Converting(NumIn)
' Convert numbers to their individual word.
Dim strY As String
Dim strString As String
Dim intX As Integer
For intX = 1 To Len(NumIn)
strY = Mid(NumIn, intX, 1)
If strY = "0" Then
strY = "10"
End If
strString = strString & Choose(Val (strY), "One", "Two",
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Zero")

Next intX
Converting = strString
End Function
======
You can call it from a control on a report, or as below, from a query:
TextWords:Converting([NumberField])

Hope this helps

I tried this by creating a module and pasting the code.
When I used Coverter([Field name]) I was taken to the VBA
code.

Please help

Thanks Fred

Fred,
What is Coverter([Field name]) ?

Where are you placing that?
In a query? As control source in a control?

The Function Name I gave you is "Converting", not "Coverter"
It doesn't matter if you changed the name of the function, as long as
you have spelled it correctly in the calling syntax..
Did you replace [NumberField] with the actual name of the field that
contains the numbers you want to spell out.
 
Hi again, I copied the code from the reply and saved in a
new module. I then opened my report and created the
field =Converting([The actual numerical field name]) in
the control of the field and previewed the report. I was
switched to the first line of the new module 'Function
Converting(NumIn)' this was in yellow. further down the
code the following was in red: strString = strString &
Choose(Val(strY), "One", "Two",
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "
Zero").

Sorry if I am being thick.
-----Original Message-----
I am trying to produce payment details on a preprinted
cheque using a report. The value of the cheque is
displayed in the report
and under this I want a separate field(s) with the
individual digits of the number shown in words eg
651,253 to be displayed
as 'Six' 'Five' 'One' 'Two' 'Five' 'Three.
I have the code that displays the value as Six Hundred
and Fifty One etc., but this is not what I want.

Someone replied with the following code:
Fred,

You can write a user defined function to return the individual number as
a text word.

Function Converting(NumIn)
' Convert numbers to their individual word.
Dim strY As String
Dim strString As String
Dim intX As Integer
For intX = 1 To Len(NumIn)
strY = Mid(NumIn, intX, 1)
If strY = "0" Then
strY = "10"
End If
strString = strString & Choose(Val (strY), "One", "Two",
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Zero")

Next intX
Converting = strString
End Function
======
You can call it from a control on a report, or as below, from a query:
TextWords:Converting([NumberField])

Hope this helps

I tried this by creating a module and pasting the code.
When I used Coverter([Field name]) I was taken to the VBA
code.

Please help

Thanks Fred
.
 
Hi again, I copied the code from the reply and saved in a
new module. I then opened my report and created the
field =Converting([The actual numerical field name]) in
the control of the field and previewed the report. I was
switched to the first line of the new module 'Function
Converting(NumIn)' this was in yellow. further down the
code the following was in red: strString = strString &
Choose(Val(strY), "One", "Two",
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "
Zero").

Sorry if I am being thick.
-----Original Message-----
I am trying to produce payment details on a preprinted
cheque using a report. The value of the cheque is
displayed in the report
and under this I want a separate field(s) with the
individual digits of the number shown in words eg
651,253 to be displayed
as 'Six' 'Five' 'One' 'Two' 'Five' 'Three.
I have the code that displays the value as Six Hundred
and Fifty One etc., but this is not what I want.

Someone replied with the following code:
Fred,

You can write a user defined function to return the individual number as
a text word.

Function Converting(NumIn)
' Convert numbers to their individual word.
Dim strY As String
Dim strString As String
Dim intX As Integer
For intX = 1 To Len(NumIn)
strY = Mid(NumIn, intX, 1)
If strY = "0" Then
strY = "10"
End If
strString = strString & Choose(Val (strY), "One", "Two",
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Zero")

Next intX
Converting = strString
End Function
======
You can call it from a control on a report, or as below, from a query:
TextWords:Converting([NumberField])

Hope this helps

I tried this by creating a module and pasting the code.
When I used Coverter([Field name]) I was taken to the VBA
code.

Please help

Thanks Fred
.

Sometimes in sending e-mail messages, long lines get split.
It may be that you copied the message and didn't reset the longer lines
to their proper length.
For instance, this line:
strString = strString & Choose(Val(strY), "One","Two",
"Three","Four","Five", "Six", "Seven", "Eight", "Nine",
"Zero")
should all be on one line, without any of the > symbols that appear at
the left side of messages.
Also make sure each of the values ("One","Two", etc.) is surrounded with
quotation marks and separated by a comma.

Open your module. Click the Compile tool button (looks like a sheaf of
papers with a down arrow). If the code is improperly written, you will
get an error message and the problem line will be highlighted.

Or....
It may be that the field you are passing to the function is a Null value
( i.e. the number field is empty).
In which case you will get an error message and the code window will
open at that point.
Add a line of code so that the first few lines look like this:

Function Converting(NumIn)
' Convert numbers to their individual word.
If IsNull(NumIn) Then Exit Function
Dim strY As String

Dim strString As String
etc.....

The function will just exit if it encounters a Null field value.
 
That works great now. Thanks for that. One adjustment
needed though. I want to ignore the pence amount, and the
leading spaces ahead of the number to return "Zero" to
10,000,000.

eg
256.15 returns Zero Zero Zero Zero Zero Two Five Six

210,256.15
returns

Zero Zero Two One Zero Two Five Six

Once again thanks for your help

Fred
-----Original Message-----
I am trying to produce payment details on a preprinted
cheque using a report. The value of the cheque is
displayed in the report
and under this I want a separate field(s) with the
individual digits of the number shown in words eg
651,253 to be displayed
as 'Six' 'Five' 'One' 'Two' 'Five' 'Three.
I have the code that displays the value as Six Hundred
and Fifty One etc., but this is not what I want.

Someone replied with the following code:
Fred,

You can write a user defined function to return the individual number as
a text word.

Function Converting(NumIn)
' Convert numbers to their individual word.
Dim strY As String
Dim strString As String
Dim intX As Integer
For intX = 1 To Len(NumIn)
strY = Mid(NumIn, intX, 1)
If strY = "0" Then
strY = "10"
End If
strString = strString & Choose(Val (strY), "One", "Two",
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Zero")

Next intX
Converting = strString
End Function
======
You can call it from a control on a report, or as below, from a query:
TextWords:Converting([NumberField])

Hope this helps

I tried this by creating a module and pasting the code.
When I used Coverter([Field name]) I was taken to the VBA
code.

Please help

Thanks Fred
.
 
I have sorted the decimal problem by using Int(Number) in
my control. I now just need the leading zeros in front of
my number.

Thanks

Fred
-----Original Message-----
That works great now. Thanks for that. One adjustment
needed though. I want to ignore the pence amount, and the
leading spaces ahead of the number to return "Zero" to
10,000,000.

eg
256.15 returns Zero Zero Zero Zero Zero Two Five Six

210,256.15
returns

Zero Zero Two One Zero Two Five Six

Once again thanks for your help

Fred
-----Original Message-----
I am trying to produce payment details on a preprinted
cheque using a report. The value of the cheque is
displayed in the report
and under this I want a separate field(s) with the
individual digits of the number shown in words eg
651,253 to be displayed
as 'Six' 'Five' 'One' 'Two' 'Five' 'Three.
I have the code that displays the value as Six Hundred
and Fifty One etc., but this is not what I want.

Someone replied with the following code:
,
"Zero")

Next intX
Converting = strString
End Function
======
You can call it from a control on a report, or as
below,
from a query:
TextWords:Converting([NumberField])

Hope this helps

I tried this by creating a module and pasting the code.
When I used Coverter([Field name]) I was taken to the VBA
code.

Please help

Thanks Fred
.
.
 
Back
Top