Text Form Field - Number Format Problem

P

Paul J

I am creating a (Word 2003) protected form using Text Form Fields to accept
input (and to perform a calculation on previously input Number fields).

The Number Format dropdown box in the Text Form Field Options menu where the
Type is Number, offers only a limited set of number of available formats.

One of these formats, £#,##0.00;(£#,##0.00), can be edited to
£#,##0;(£#,##0) to allow input of values of whole Pounds (Sterling) only.
HOWEVER, I am not happy with the format of the negative values (i.e. in
parentheses) and I would REALLY prefer to use "£,0;-£,0".

I am able to use my prefered number format to display the result in the
Calculation type of Text Form Field - but I have been unable to see how I can
apply this format to a(n input) Number type Text Form Field.

Can anybody help, please?

PJ
 
P

Peter Jamieson

I don't thin kyou can actually constrain what a user types in these fields,
at least not just using the properties of the "text form field". When you
specify a "text form field" type of number, all that happens is that Word
tries to interpret whatever the user types as a number. If, for example, the
user types "a", Word strips the "a", regards the value as "0", and formats
that value according to the |"Number Format" you set u p in the field's
properties.

So, you have probably already noticed that if you use the provided "number
format" "£#,##0.00;(£#,##0.00)", then if the user actually enters "-2", they
see (£2.00) in the field. But they are not, for example, constrained to use
(£2) to indicate a negative amount.

In other words,
a. as far as I know, you can't constrain what a user actually types into a
Word text form field /while they are typing/
b. the "language" used to specify what the output should look like if the
user typed a negative entry does not seem to be the same as the language you
can use in a regular numeric field switch (\#), and does not appear to be
documented anywhere.
c. You can probably only constrain what the user types and format the
result how you want by using an Exit macro.

Perhaps others know better but otherwise, sorry, tha't the way it is. and I
wouldn't expect Word 2007 content controls to improve things either. .

Peter Jamieson
 
G

Graham Mayor

Further to Peter's comments, don't use the form fields to perform the
calculations, use a calculated field eg
{ ={ Text1 } + { Text2 } \# "£,0.00;-£,0.00" } For this calculation to work
it must be in the body of the document and the relevant form field calculate
on exit check boxes must be checked.

To format the form fields themselves you can run macros on exit from the
relevant fields (which for this to work should be set as text fields).

At their simplest the macros could be something like

Sub GetContent()
Dim oFld As FormFields
Dim strNum As String
Set oFld = ActiveDocument.FormFields
strNum = oFld("Text1").Result
oFld("Text1").Result = Format(strNum, "£#,##0.00")
End Sub

Sub GetContent2()
Dim oFld As FormFields
Dim strNum As String
Set oFld = ActiveDocument.FormFields
strNum = oFld("Text2").Result
oFld("Text2").Result = Format(strNum, "£#,##0.00")
End Sub

etc

http://www.gmayor.com/installing_macro.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top