Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
owen owen is offline
external usenet poster
 
Posts: 61
Default Form Field Number Format Problem

I am attempting to determine the format code i need to enter in a numeric
form field.

The following are my parameters:

The format i am trying to achieve is:

### ### ###.##

I always require two decimal places, even if the user only inputs the
integer value.
I require a space between each 3 consecutive digits.
I do not want to show any leading zeros.

For example, the formatted fields appear as

456 345.23
2 456 345.23

Thanks in advance for any help, i do not seem to be able to achieve the
desired result through using # or 0 or any combination of them.
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Form Field Number Format Problem

Run a macro containing the following code on exit from the formfield (Change
the Text1 to the bookmark name assigned to the formfield)

Dim IntPart as String, DecPart as String
With ActiveDocument.FormFields("Text1")
If IsNumeric(.result) Then
If InStr(.result, ".") 0 Then
IntPart = Left(.result, InStr(.result, ".") - 1)
DecPart = Mid(.result, InStr(.result, "."))
If Len(DecPart) = 2 Then
DecPart = DecPart & "0"
End If
Else
IntPart = .result
DecPart = ".00"
End If
Select Case Len(IntPart)
Case Is 4
IntPart = IntPart
Case 4
IntPart = Left(IntPart, 1) & " " & Mid(IntPart, 2)
Case 5
IntPart = Left(IntPart, 2) & " " & Mid(IntPart, 3)
Case 6
IntPart = Left(IntPart, 3) & " " & Mid(IntPart, 4)
Case 7
IntPart = Left(IntPart, 1) & " " & Mid(IntPart, 2, 3) & " "
& Mid(IntPart, 5)
Case 8
IntPart = Left(IntPart, 2) & " " & Mid(IntPart, 3, 3) & " "
& Mid(IntPart, 6)
Case 9
IntPart = Left(IntPart, 3) & " " & Mid(IntPart, 4, 3) & " "
& Mid(IntPart, 7)
End Select
.result = IntPart & DecPart
Else
MsgBox "You have not entered a number"
End If
End With

From the above you should be able to deduce the results to be used for cases
where the length of the integer part of the number is greater than 9 digits.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"Owen" wrote in message
...
I am attempting to determine the format code i need to enter in a numeric
form field.

The following are my parameters:

The format i am trying to achieve is:

### ### ###.##

I always require two decimal places, even if the user only inputs the
integer value.
I require a space between each 3 consecutive digits.
I do not want to show any leading zeros.

For example, the formatted fields appear as

456 345.23
2 456 345.23

Thanks in advance for any help, i do not seem to be able to achieve the
desired result through using # or 0 or any combination of them.


  #3   Report Post  
Posted to microsoft.public.word.docmanagement
owen owen is offline
external usenet poster
 
Posts: 61
Default Form Field Number Format Problem

Doug

That is brilliant, not sure i'll ever grasp the Visual Basic concept like
you guys on here, but i'll keep having a crack.

Thanks also to Macropod and Graham for your replies.

"Doug Robbins - Word MVP" wrote:

Run a macro containing the following code on exit from the formfield (Change
the Text1 to the bookmark name assigned to the formfield)

Dim IntPart as String, DecPart as String
With ActiveDocument.FormFields("Text1")
If IsNumeric(.result) Then
If InStr(.result, ".") 0 Then
IntPart = Left(.result, InStr(.result, ".") - 1)
DecPart = Mid(.result, InStr(.result, "."))
If Len(DecPart) = 2 Then
DecPart = DecPart & "0"
End If
Else
IntPart = .result
DecPart = ".00"
End If
Select Case Len(IntPart)
Case Is 4
IntPart = IntPart
Case 4
IntPart = Left(IntPart, 1) & " " & Mid(IntPart, 2)
Case 5
IntPart = Left(IntPart, 2) & " " & Mid(IntPart, 3)
Case 6
IntPart = Left(IntPart, 3) & " " & Mid(IntPart, 4)
Case 7
IntPart = Left(IntPart, 1) & " " & Mid(IntPart, 2, 3) & " "
& Mid(IntPart, 5)
Case 8
IntPart = Left(IntPart, 2) & " " & Mid(IntPart, 3, 3) & " "
& Mid(IntPart, 6)
Case 9
IntPart = Left(IntPart, 3) & " " & Mid(IntPart, 4, 3) & " "
& Mid(IntPart, 7)
End Select
.result = IntPart & DecPart
Else
MsgBox "You have not entered a number"
End If
End With

From the above you should be able to deduce the results to be used for cases
where the length of the integer part of the number is greater than 9 digits.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"Owen" wrote in message
...
I am attempting to determine the format code i need to enter in a numeric
form field.

The following are my parameters:

The format i am trying to achieve is:

### ### ###.##

I always require two decimal places, even if the user only inputs the
integer value.
I require a space between each 3 consecutive digits.
I do not want to show any leading zeros.

For example, the formatted fields appear as

456 345.23
2 456 345.23

Thanks in advance for any help, i do not seem to be able to achieve the
desired result through using # or 0 or any combination of them.



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default Form Field Number Format Problem

Hi Owen,

If you make the formfield type numeric, you can specify the number format as:
### ### ##0.00


--
Cheers
macropod
[Microsoft MVP - Word]


"Owen" wrote in message ...
I am attempting to determine the format code i need to enter in a numeric
form field.

The following are my parameters:

The format i am trying to achieve is:

### ### ###.##

I always require two decimal places, even if the user only inputs the
integer value.
I require a space between each 3 consecutive digits.
I do not want to show any leading zeros.

For example, the formatted fields appear as

456 345.23
2 456 345.23

Thanks in advance for any help, i do not seem to be able to achieve the
desired result through using # or 0 or any combination of them.

  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Form Field Number Format Problem

You could do that but you are reliant on the user entering the decimal. Try
it with 12345

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



macropod wrote:
Hi Owen,

If you make the formfield type numeric, you can specify the number
format as: ### ### ##0.00



"Owen" wrote in message
...
I am attempting to determine the format code i need to enter in a
numeric form field.

The following are my parameters:

The format i am trying to achieve is:

### ### ###.##

I always require two decimal places, even if the user only inputs the
integer value.
I require a space between each 3 consecutive digits.
I do not want to show any leading zeros.

For example, the formatted fields appear as

456 345.23
2 456 345.23

Thanks in advance for any help, i do not seem to be able to achieve
the desired result through using # or 0 or any combination of them.





  #6   Report Post  
Posted to microsoft.public.word.docmanagement
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default Form Field Number Format Problem

Hi Graham,

Works for me - 12345 gets displayed as 12 345.00, which accords with the OP's requirement (I always require two decimal places, even
if the user only inputs the integer value).

--
Cheers
macropod
[Microsoft MVP - Word]


"Graham Mayor" wrote in message ...
You could do that but you are reliant on the user entering the decimal. Try it with 12345

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



macropod wrote:
Hi Owen,

If you make the formfield type numeric, you can specify the number
format as: ### ### ##0.00



"Owen" wrote in message
...
I am attempting to determine the format code i need to enter in a
numeric form field.

The following are my parameters:

The format i am trying to achieve is:

### ### ###.##

I always require two decimal places, even if the user only inputs the
integer value.
I require a space between each 3 consecutive digits.
I do not want to show any leading zeros.

For example, the formatted fields appear as

456 345.23
2 456 345.23

Thanks in advance for any help, i do not seem to be able to achieve
the desired result through using # or 0 or any combination of them.




  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Form Field Number Format Problem

How odd - here I get 12 3.45 in both Word 2003 and 2007 using that switch?

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




macropod wrote:
Hi Graham,

Works for me - 12345 gets displayed as 12 345.00, which accords with
the OP's requirement (I always require two decimal places, even if
the user only inputs the integer value).

"Graham Mayor" wrote in message
...
You could do that but you are reliant on the user entering the
decimal. Try it with 12345 --

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



macropod wrote:
Hi Owen,

If you make the formfield type numeric, you can specify the number
format as: ### ### ##0.00



"Owen" wrote in message
...
I am attempting to determine the format code i need to enter in a
numeric form field.

The following are my parameters:

The format i am trying to achieve is:

### ### ###.##

I always require two decimal places, even if the user only inputs
the integer value.
I require a space between each 3 consecutive digits.
I do not want to show any leading zeros.

For example, the formatted fields appear as

456 345.23
2 456 345.23

Thanks in advance for any help, i do not seem to be able to achieve
the desired result through using # or 0 or any combination of them.



  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Form Field Number Format Problem

Same here, even if I modify the digit grouping symbol in the Control
PanelRegional and Language Options. It was only after trying all sorts of
formatting switches that I resorted to creating the macro.

Wait a minute, it does work if you use Ctrl+Shift+Spacebar to insert the
space in the formatting switch

# ##0.0

Also, the switch shown above is all that is required no matter how many
digits are contained in the number

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"Graham Mayor" wrote in message
...
How odd - here I get 12 3.45 in both Word 2003 and 2007 using that
switch?

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




macropod wrote:
Hi Graham,

Works for me - 12345 gets displayed as 12 345.00, which accords with
the OP's requirement (I always require two decimal places, even if
the user only inputs the integer value).

"Graham Mayor" wrote in message
...
You could do that but you are reliant on the user entering the
decimal. Try it with 12345 --

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



macropod wrote:
Hi Owen,

If you make the formfield type numeric, you can specify the number
format as: ### ### ##0.00



"Owen" wrote in message
...
I am attempting to determine the format code i need to enter in a
numeric form field.

The following are my parameters:

The format i am trying to achieve is:

### ### ###.##

I always require two decimal places, even if the user only inputs
the integer value.
I require a space between each 3 consecutive digits.
I do not want to show any leading zeros.

For example, the formatted fields appear as

456 345.23
2 456 345.23

Thanks in advance for any help, i do not seem to be able to achieve
the desired result through using # or 0 or any combination of them.




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Format form field for phone number Nina Microsoft Word Help 2 April 10th 09 09:58 PM
puzzling number format problem in conditional field Jesse[_3_] Mailmerge 5 October 5th 07 04:23 AM
form field format for phone number Jan Microsoft Word Help 4 March 9th 07 04:18 AM
Syntax for Number format in the Text Form Field Options Ed Hall 61 Microsoft Word Help 3 May 8th 05 07:51 PM
form field,can I add a telephone number under the number field w/d redwolfe5 Microsoft Word Help 3 March 3rd 05 05:30 PM


All times are GMT +1. The time now is 12:29 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"