View Single Post
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Lenny Lenny is offline
external usenet poster
 
Posts: 74
Default Percent formatted field makes me enter as .10

Graham: the revised code worked perfectly... a question though. When
tabbing from another form field, into the "text1" field, everythings fine as
long as you actually enter a number and tab out. If you try to tab thru the
field (not entering a number) you get a "run time error (13)". Can this be
corrected? Lenny

"Graham Mayor" wrote:

I am not surprised it didn't work - something odd happened there during the
transcribing of the code

Sub Percentage()
Dim oFld As FormFields
Dim sRes As String
Dim sDec As String
Set oFld = ActiveDocument.FormFields
sRes = oFld("Text1").Result
If InStr(1, sRes, "%") Then
sRes = Replace(sRes, "%", "")
End If
If sRes = Int(sRes) Then
sDec = "###%"
Else
sDec = "###.##%"
End If
oFld("Text1").Result = Format(sRes / 100, sDec)
End Sub

is what it should have been. Apologies )


--

Graham Mayor - Word MVP

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



Lenny wrote:
Lenny he
Graham - I too have the same problem, however, when I copied your
code into my module, I started getting errors when trying to run the
code. It did not like the second to last End Sub= statement
(indicating it could only be used with comments), when I deleted it
and ran the code, it did not care for the If sRes = Int(sres) ... at
that point, I thought I would come back to the source. I am running
Word 2003. Regards

"Graham Mayor" wrote:

If you want to enter 10 and have it display as 10% you are going to
need perform a calculation on that field which will need vba. The
following macro run on exit from the form field in question (which
should be set as text type) will allow you to enter 10 to produce
10% and 10.5 to produce 10.5% etc. when you tab out of that field.
The macro assumes the field is bookmarked Text1

Sub Percentage()
Dim oFld As FormFields
Dim sRes As String
Dim sDec As String
Set oFld = ActiveDocument.FormFields
sRes = oFld("Text1").Result
If InStr(1, sRes, "%") Then
sRes = replace(sRes, "%", "")
End If
If sRes = Int(sRes) Then
sDec = "###%"
Else
sDec = "###.##%"
End If
oFld("Text1").Result = Format(sRes / 100, sDec)
End Sub= Format(sRes / 100, "###.00%")
End Sub


--

Graham Mayor - Word MVP

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


lauralee08 wrote:
I have my form field set up as a percent, in Excel I am used to just
entering "10", and it will convert to "10%" or "10.00%", but Word is
changing that same entry to "1000%". It makes me enter as ".10",
which is just stupid that I have to do that only in Word and nowhere
else. Does anyone know a way to change this so I can enter 10 and
get 10%?