View Single Post
  #8   Report Post  
Greg Maxey
 
Posts: n/a
Default

Ricki,

This is ugly, but close. I ran a test on two formfields and summed the
results. Probably to much trouble to pursue.

Set your formfields as regular text
Run this macro on entry
Sub GetIndex()
Dim oDoc As Document
Set oDoc = ActiveDocument
oDoc.Variables("Index").Value = oDoc.Range(0,
Selection.Bookmarks(1).Range.End).Bookmarks.Count
End Sub

Run this macro on exit
Sub Test()

Dim oDoc As Document
Dim i As Long
Set oDoc = ActiveDocument
i = CStr(oDoc.Variables("Index").Value)
Dim a As String
Dim b As String
oDoc.Variables("Text1").Value = oDoc.Bookmarks("Text1").Range.Text
oDoc.Variables("Text2").Value = oDoc.Bookmarks("Text2").Range.Text
a = oDoc.Variables("Text1").Value
b = oDoc.Variables("Text2").Value
Do
a = Mid$(a, 2)
Loop Until IsNumeric(Left$(a, 1))
Do
b = Mid$(b, 2)
Loop Until IsNumeric(Left$(b, 1))
oDoc.Variables("Result1").Value = Format(Val(a) + Val(b), "$## ### ##0.00")
oDoc.FormFields(i).Result = Format(oDoc.FormFields(i).Result, "$## ###
##0.00")
oDoc.Fields.Update
End Sub

My brain is fried and I can't think of anything else.
--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Ricki Miles wrote:
Thanks for all you efforts, Greg. I wish there was another way to
have text protected in Word - Form fields are very limiting.

Ricki

"Greg Maxey" wrote in message
...
Ricki,

I am totally stumped. I even tried changing the number separator in
Control Panel Regional and Language settings to a space vice a
comma but I still can't get it to work. I am working with Word2003
now (Word2000 earlier) and now I can't even get 1234 to look like $1
234.00 it comes out $ 1 2.34 :-(

I tried using VBA on exit to take the formfield result and format it
and feed it back, but this doesn't work either:

Text1.Result = Format(Text.Result, "$# ###.00")

If I think of anything I will post back

--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

Ricki Miles wrote:
That's exactly my problem. Can you think of another solution? The
client needs a template that is "locked down" so users cannot
changes existing text and formatting - thus, the protected form
fields. But
the number corporate standard is a space instead of a comma and the
fields need to calculate properly.

I have tried many things, but nothing seems to work. Formatting can
be customized like this in Excel. Do you think this form should
have
an on exit macro that takes the numbers from Word into Excel,
formats them and sends them back? I wouldn't know how to write the
macro to
go from one program to another. I would be happy to make the form
with macrobuttons and empty fields (control+F9), but then there is
no protecting the text from users who want to change it.

Thanks for the help,

Ricki
"Greg" wrote in message
oups.com...
Ricki,

Now I see your problem, I just selected the standard format

$#,##0.00;($#,##0.00)

Replaced the commas with spaces:

$# ##0.00;($# ##0.00)

and ran some test.

1 returns $1.00
1234 returns $1 234.00

however the calculations are treating the 1 234 as two numbers.
If I add

$ 1 234.00 and $2.00 I am getting $237.00 or 1 + 234 + 2

I am stumped right now :-(