Another question on variables

A

Andre

What does this code do:

ActiveDocument.Variables.Add Name:="BeltLength"
ActiveDocument.FormFields("BeltLength").Result = BeltLength

Shouldn't those two lines work in establishing a document variable
called BeltLength and then assigning the value of the text FormField
bookmarked as BeltLength to the document variable BeltLength?

What am I doing wrong here? I'm not doing anything else in the macro,
just those two lines plus the customary sub and end sub.

Thank you again.


Andre S
 
D

DeeJee

ActiveDocument.Variables.Add Name:="BeltLength"
ActiveDocument.FormFields("BeltLength").Result = BeltLength

Shouldn't those two lines work in establishing a document variable
called BeltLength and then assigning the value of the text FormField
bookmarked as BeltLength to the document variable BeltLength?


Try it like this:

Sub ResultFromFieldInDocToVar()
Dim Tmp
Tmp = ActiveDocument.FormFields("BeltLength").Result
ActiveDocument.Variables.Add Name:="BeltLength", Value:=Tmp
End Sub

Sub SetResultFromVarToDoc()
ActiveDocument.FormFields("BeltLength2").Result = _
ActiveDocument.Variables.Item("BeltLength").Value
End Sub
 
D

Doug Robbins - Word MVP

Hi Andre,

Use

ActiveDocument.Variables("BeltLength").Value =
ActiveDocument.FormFields("BeltLength").Result

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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