Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Tue, 19 Aug 2008 07:55:01 -0700,    group: microsoft.public.word.vba.general        back       


Evaluating the content of a variable   
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.
date: Tue, 19 Aug 2008 07:55:01 -0700   author:   bz

Re: Evaluating the content of a variable   
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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
all may benefit.

bz wrote:
> 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.
date: Tue, 19 Aug 2008 12:42:49 -0400   author:   Jay Freedman

Re: Evaluating the content of a variable   
Thanks, this clears up all of my problems!

"Jay Freedman" wrote:

> 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        FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
> all may benefit.
> 
> bz wrote:
> > 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. 
> 
> 
>
date: Thu, 21 Aug 2008 11:54:00 -0700   author:   bz

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us