View Single Post
  #8   Report Post  
Posted to microsoft.public.word.docmanagement
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default How can you round a number in a non-calculating field?

Hi jerye,

You can only achieve what you're after with vba. You could for example, use code like:
Option Explicit
Dim FfName As String

Sub GetFF()
FfName = Selection.Bookmarks(1).Name
End Sub

Sub RoundIt()
ActiveDocument.FormFields(FfName).Result = Round(ActiveDocument.FormFields(FfName).Result, 0)
End Sub
in a normal code module and make 'GetFF' the 'On Entry' macro and 'RoundIt' the 'On Exit' for the formfield, which must also have a
bookmark name.

If the formfield is formatted as text, you'll get a result equal to the rounded number, with no decimals. If the formfield is
formatted as number, you'll need to have at least one decimal, and the returned result will be the whole number plus '.0' (or
however many decimals you're using).

Note: If the formfield you're dealing with is the first in the document, you'll also need to use code like the following in the
document's 'This Document' module:

Option Explicit

Private Sub Document_Open()
Call GetFF
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


"Jerye" wrote in message ...
What I am needing is to be able type in 14.9 and it will round to 15 or 14.3
and it will round to 14. Word always rounds down, no matter what. This is not
a calulating form field, so I can't put in a formula.

Jerye

"Jerye" wrote:

I have a form field that needs to be rounded, but it is not a calculating
form field, it is the field used in the calculation of another form field. Is
there a way to do this?

Jerye