Form Field Expression

J

Jim Faraone

I need to change or clear a Form Field "Expression" programmatically,
However, This property does not seem to be exposed in VBA and can only be
changed using the Form Field Properties UI. Has anyone ever done this or
does anyone have any suggestions? Thanks Jim.
 
P

Peter Hewett

Hi Jim Faraone

You can adapt the following to do what you want. It demonstrates the properties you need
to use:

Public Sub FormFieldCalculation()
Dim ffItem As Word.FormField

Set ffItem = ActiveDocument.FormFields("Text3")

' Make sure it's a TextBox FormField
With ffItem.TextInput
If .Valid Then

' It must also be a calculation
If .Type = wdCalculationText Then
.Default = "=Text1 + Text2"
End If
End If
End With
End Sub

The example assumes you have 3 TextInput FormFields named: "Text1", "Text2" and "Text3".
The code sets FormField "Text3" to have a calculated value of "Text1 + Text2".

Just beware if you change the calculation dynamically that the type of the FormFields
that make up the calculation contain valid data. You may also need to set the
CalculateOnExit property for these FormFields as well.

HTH + Cheers - Peter
 

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