Office Word Programming >> Bookmark & IF Statement - always result the else statement

by kushkusha » Sun, 17 May 2009 16:38:57 GMT

Hello,

I am trying to use the conditinal text field, But the result is always
the text that appears as the "Else" text.
I have no idea why?
Here is the code (I Tried several ways - but the result is always the
same):
{ IF "{ REF PrivateCar }" = "1" YES NO}

The result is always NO.
I Pu the PrivateLine in a row before - to see what is the value in it
- and it does contain the value "1"

Any help or idea would be appritioated,
Many thanks,
Malka



Office Word Programming >> Bookmark & IF Statement - always result the else statement

by Graham Mayor » Sun, 17 May 2009 17:26:48 GMT


The following will produce YES
{ SET PrivateCar 1 }{ IF { REF PrivateCar } = 1 "YES" "NO" }
If that does so, remove the SET field and update the conditional field.
If that doesn't produce YES then the PrivateCar bookmark does not contain 1

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>








Office Word Programming >> Bookmark & IF Statement - always result the else statement

by pinukforum » Sun, 17 May 2009 20:39:26 GMT

I did it... OK it got YES when I did the SET before. and after remove
it - it contains NO - akthough - when the bookmark is show on the soc
is seems to contain the value "1".

So this not help so much....

Maybe I need to add some VBA code? Or do I have any option to see in
"debug" what is the real value - although I see "1"??

Many thanks,
Malka






Bookmark & IF Statement - always result the else statement

by Graham Mayor » Sun, 17 May 2009 21:05:34 GMT

What EXACTLY does {REF PrivateCar} produce?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>









Bookmark & IF Statement - always result the else statement

by Graham Mayor » Sun, 17 May 2009 21:16:56 GMT

On further reflection, is this information coming from a form field check
box? If so you will need macro code to resolve the issue. Assuming the
checkbox is called PrivateCar, run the following macro on exit from the
check box form field

Sub Checked()
If ActiveDocument.FormFields("PrivateCar").CheckBox.Value = True Then
For Each aVar In ActiveDocument.Variables
If aVar.name = "sCheck1" Then num = aVar.Index
Next aVar
If num = 0 Then
ActiveDocument.Variables.Add name:="sCheck1", Value:="YES"
Else
ActiveDocument.Variables(num).Value = "YES"
End If
End If

If ActiveDocument.FormFields("PrivateCar").CheckBox.Value = False Then
For Each aVar In ActiveDocument.Variables
If aVar.name = "sCheck1" Then num = aVar.Index
Next aVar
If num = 0 Then
ActiveDocument.Variables.Add name:="sCheck1", Value:="NO"
Else
ActiveDocument.Variables(num).Value = "NO"
End If
End If
End Sub

Then use a DocVariable field rather than a conditional field
{DocVariable sCheck1)
to display the result YES or NO


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>









Bookmark & IF Statement - always result the else statement

by Jean-Guy Marcil » Mon, 18 May 2009 03:17:36 GMT

Graham Mayor was telling us:
Graham Mayor nous racontait que :


Just wondering, couldn't the above code be replaced by?

If ActiveDocument.FormFields("PrivateCar").CheckBox.Value = True Then
ActiveDocument.Variables("sCheck1").Value = "YES"
End If

???

If the DocVariable does not exist it is automatically created, so is there a
particular reason for doing all that?

--
______________________________
Jean-Guy Marcil
Montreal, Canada




Bookmark & IF Statement - always result the else statement

by kushkusha » Mon, 18 May 2009 14:46:23 GMT

n May 17, 4:16m, "Graham Mayor" < XXXX@XXXXX.COM > wrote:
> faVar.name = "sCheck1" Then num = aVar.In>ex
> Next>aVar
> fnum = > Then
> ActiveDocument.Variables.Add name:="sCheck1", Va>ue:="YES"> > Else
> ActiveDocument.Variables(nu>).Value = >YES"
> > gt;EndIf
> EndIf
>
> IfActiveDocument.FormFields("PrivateCar").CheckBox.>alue = False Then
> For Each aVar In Acti>eDocument.Variables
> faVar.name = "sCheck1> Then num = aV>r.Index
> Next>aVar
> fnum = 0 Then
> ActiveDocument.Variables.Ad> name:="s>heck1", Value:="NO"
> Else
> Active>ocument.Va>iables(n>m).Value =>"N>"
> EndIf
> EndIf
> End Sub
>
> Then use a DocVariable>field rather than a cond>tional field
> {DocVariable sChec>1)> > to>di>>la> t>e>re>ul>>YE> <&g<; <<gt;<<t;<> <gt<<gt< -><
&g<; <<>< ><<> ><<> <>>< ><<> <>><><>><<>
> Graham Mayor - o>d MVP
>
> My web sitewww.gmayor.com
>>Wo>> M>P >e> s>te>>tp>/<>o<>&<t;mvp&g<<&g<;o<&g<<
<gt< <&g<<><>><>> ><<> <>>< ><<> <>>< <>><<>
>
> XXXX@XXXXX.COM wrote:
> > I did it... OK it got YES when > >id the SET before. and after remove
> > it - it contains NO - akthoug> > when thebookmarkis show on the soc
>
> > Maybe I need to add some VBA c>d>? Or do I have any option to see in
> > "debug" what is>th> >eal value - alt>o>gh I see>"1>?>
>
> > Many thanks,
> > Malka
>
> > On May 17< 12:26 pm, ">raham May>r>>< XXXX@XXXXX.COM > wrote> >> >> The following will produce YES
> >> { SET PrivateCar 1 }{IF{ R>F>>rivateCar } = 1 "YES" "NO" }Ifthat
> >> does so, remove th> >>T field and update the conditional
> >> field.Ifthat doesn't produce Y>S>>hen the Priv>te>a>>ookma>k>>es>>ot> >>>> c>nt>>n >
&g<;&<<;>><<gt<&g<; <<gt< >> <gt;>>< ><<> ><<> <>>< ><<> <>>> <>>>>>
> >> Graham Mayor - Word >V>> >
> >> My web sitewww.gmayor.com
> >>>W>>d >>P >eb>s>te>tt>>//>o<>.m>><<o&g<<&g<; <&g<< ><gt< <&g<;>>>><<> ><<> <>>< ><<> <>>< <>><>>>>>
> >> ku>hk>.>>>gmail.com wrote:
> >>> Hello,
>
> >>> I am trying to use the co>d>>>nal text field, But the result is
> >>> always the>t>>> that appears as the ">l>>> text.
> >>> I have no idea why?
> >>> Here is the code (I Tried s>v>>>l ways - but >h>>>esult is always
> >>> the same):
> >>>>{I>">>>EF PrivateCar }" = "1" YES >O>>>>
> >>> The result is always NO.
> >>> I Pu the PrivateLine in a ro> >>>ore - to see what is the value in
> >>> >t > >>> it does contain the value "1"
>
> >>> A>y>>>lp or idea woul> >>>appritioated,
> >>> Many th>nk>,>>> >>> Malka- Hide quoted text -
>
> >> - >ho> quoted text -- Hide quoted text -
>
> - Show quoted text -

No, The value is comming while openning the document (via VB program).
I try to do the same on other bookmark - Job_Percent But the result is
the same - always the else value.
Any additional ideas?
Many than

Bookmark & IF Statement - always result the else statement

by Graham Mayor » Mon, 18 May 2009 14:59:38 GMT

You are right - that's what comes of reproducing other people's code without
checking the motivation behind it :(

I don't have older Word versions than 2003 to check, but wonder if the extra
lines were necessary in 97 or 2000? Either way the macro did work as
originally stated and that is all that matters in the final, analysis ;)

The macro can be more simply written as

Sub Checked()
If ActiveDocument.FormFields("PrivateCar").CheckBox.Value = True Then
ActiveDocument.Variables("sCheck1").Value = "YES"
Else
ActiveDocument.Variables("sCheck1").Value = "NO"
End If
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>







Bookmark & IF Statement - always result the else statement

by Graham Mayor » Mon, 18 May 2009 15:04:16 GMT





You didn't answer the basic question - what exactly does {REF PrivateCar}
alone produce?
I strongly suspect that your code will need to update the field when you
have changed the content. REF fields do not update automatically.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>




Bookmark & IF Statement - always result the else statement

by Peter Jamieson » Mon, 18 May 2009 16:51:38 GMT

A more basic question: Are /all/ the field code brace pairs {} the sort
that you can insert using ctrl-F9?


Peter Jamieson

http://tips.pjmsn.me.uk




Similar Threads

1. which statement right , question isChoose the correct statement?

Choose the correct statement 

1.. Word document can be saved a web page and then converted back to a word 
document
2...Can be saved as web pages but cannot be converted back to word document
3...Word document cannot be saved as web pages
4...Word document cannot be saved as web pages and web page cannot be 
converted to the word document.

2. Using OR statements in an If, then, else statement

3. Multiple "OR" statements in a single "IF" statement

I've got a document that would be MUCH easier if I could just do
something like {IF { MERGEFIELD FieldName} = "A" or "B" or "C" or "D"
then "Print this text" otherwise "print this text"} - I've seen some
pretty complex nested IF statements.  Is there an easier way to do
this?  Maybe Microsoft could help enhance this capability in the
future.  Any thoughts?

4. Executing a macro based on the results of an "If" Statement - Microsoft Office

5. Mailmerge with "If" statement producing unexpected results

Hi there

I'm using the below code for my mail merge.

Problem is that when there is a "/" in the Street1 or Street2 fields, I get 
a bunch of characters on that line that shouldn't be there.

Can anyone shed any light as to what might be going wrong - I built this 
statement by looking around on the net - I'm very much a novice when it comes 
to this stuff.

If it is relevant, I'm using Word 2003 with the data being pulled from an 
Excel 2003 spreadsheet.

Thanks
Griffo

6. Word 2002 mail merge IF statement invalid date results

7. adding a page break as a result of an IF statement

I have searched and searched -- not finding my answer.

Maybe someone here can help!

During a merge, I need to do a page break if a certain condition is
true.  What code do I enter to get a page break?

I then also wondered if it was possible to call a VBA subroutine in the
middle of a merge as a result of an IF condition...?

-Chris R
 XXXX@XXXXX.COM 

8. If statement returning true result when should be false