Evaluating the content of a variable

B

bz

This may be a duplicate post, if so could you repeat any answers? Thanks!

I have a series of repeating FormFields representing questions which are
identical except for the FormField name (e.g. location1, location2). Rather
than capture the answers via a hardcoded routine, I want to loop through the
fields, dynamically building the FormField name based on the loop value. For
example:
strLocation = "ActiveDocument.FormFields(""location" & Trim(str(i)) &
""").Result"

This produces an accurate value (i.e.,
ActiveDocument.FormFields("location1").Result, when the loop value is 1); but
I want to use it in an If statement in order to base action on the Result
value. To do this I need to be able to evaluate the value of the string
rather than just pick up the name. I can't find any functions to do this.

If I assign a FormField value to a string, then I can use the string in an
If statement, but this means more hardcoding: e.g.,
strLocation = ActiveDocument.FormFields("location1").Result
If strLocation = "Y" Then...

Thanks in advance for any help, or alternative approaches.
 
J

Jay Freedman

You just went overboard on the double quotes. You don't need a string
variable that contains the entire string
"ActiveDocument.FormFields("location1").Result", because there is no way to
"evaluate" that. Instead, you want to execute the assignment of the Result
to a string variable:

strFieldResult = ActiveDocument.FormFields("location" & Trim(str(i))).Result

and then strFieldResult will contain "Y" or "N" or whatever is in that
field.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
B

bz

Thanks, this clears up all of my problems!

Jay Freedman said:
You just went overboard on the double quotes. You don't need a string
variable that contains the entire string
"ActiveDocument.FormFields("location1").Result", because there is no way to
"evaluate" that. Instead, you want to execute the assignment of the Result
to a string variable:

strFieldResult = ActiveDocument.FormFields("location" & Trim(str(i))).Result

and then strFieldResult will contain "Y" or "N" or whatever is in that
field.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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