View Single Post
  #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.