Bookmark & IF Statement - always result the else statement

K

kushkusha

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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

pinukforum

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
 
G

Graham Mayor

What EXACTLY does {REF PrivateCar} produce?

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jean-Guy Marcil

Graham Mayor was telling us:
Graham Mayor nous racontait que :
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

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?
 
K

kushkusha

On further reflection, is this information coming from a form field check
box?Ifso 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()IfActiveDocument.FormFields("PrivateCar").CheckBox.Value =True Then
    For Each aVar In ActiveDocument.Variables
       IfaVar.name = "sCheck1" Then num = aVar.Index
    Next aVar
   Ifnum = 0 Then
        ActiveDocument.Variables.Add name:="sCheck1", Value:="YES"
    Else
        ActiveDocument.Variables(num).Value = "YES"
    EndIf
EndIf

IfActiveDocument.FormFields("PrivateCar").CheckBox.Value = False Then
    For Each aVar In ActiveDocument.Variables
       IfaVar.name = "sCheck1" Then num = aVar.Index
    Next aVar
   Ifnum = 0 Then
        ActiveDocument.Variables.Add name:="sCheck1", Value:="NO"
    Else
        ActiveDocument.Variables(num).Value = "NO"
    EndIf
EndIf
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 sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>









- 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 thanks,
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

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 thanks,

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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