Error: unknown op code for conditional

G

Guest

Hi, I'm using fields that will fill in text depending on values from a
dropdown box. I'm using IF and OR along with COMPARE field codes.
Everything looks good but when I toggle field codes I get an: Error! Unknown
op code for conditional. Here's the code I'm using
{IF {=OR ({COMPARE{MERGERFIELD Dropdown1}="113-25F1"},{COMPARE{MERGERFIELD
Dropdown1}= "113-25W4"})}=1 "2" {IF {=OR({COMPARE{MERGERFIELD
Dropdown1}="131-TAITC"}, {COMPARE{MERGEFIELD Dropdown1} ="131-F13-SGI"},
{COMPARE{ MERGEFIELD Dropdown1}="113-25U4"})}=1 "" "1"}"}

And that's it. I thought I followed the example in help, but I always get
an Error: unknown op code for conditional. Anyone know what I'm doing wrong.
Can I even do this. Thanks

Rick
 
G

Graham Mayor

What is this field structure *supposed* to do?

Did you enter the fields using CTRL+F9 for each set of field boundaries?

There is no such field type as Mergerfield - it should be Mergefield

However as you are using dropdown fields this suggests a form so Mergefields
are not relevant at all.
You should consider instead REF fields thus {REF Dropdown1} or simply
{Dropdown1}

Rather than attempt to debug this lash-up let us know what it is you have
and what you want to end up with and we should be able to suggest the way to
achieve it.

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

My web site www.gmayor.com

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

Guest

OK, I guess I wasn't clear enough with what this is supposed to do. When
the user selects an item from a dropdown box the form field fills in the
appropriate value on the form.
Yes all field boundaries were set using CTRL + F9. As far as the Mergefield
field type, that's right form the Help for fields (I didn't make it up or
something).
I also tried (REF Dropdown1) and that didn't work either. I just want to
know if you know what "unknown op code" I'm using.
And if you don't want to help, then don’t. Save the condescending attitude
for someone else. I've worked with these things before and I have some idea
of what I'm doing. If I had any other resources to use to solve this
problem, believe me I would have. Thanks for your time

Rick W.

Rick W.
 
S

Suzanne S. Barnhill

You do not need a form field for the REF field. Just insert it as a field in
plain text (no form field).

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
G

Guest

Hi Suzanne:
I'm not sure I understand. I'm using selections from the dropdown box
(i.e. "113-25F1") as criteria to determine what value will be displayed in
the form field. The format and syntax in my example was taken directly from
the MS Word Help. If there's anything incorrect with that syntax or any of
the key words, let me know. The previous responder had nothing but negative
criticism and very little help to offer. Thanks for your timely response and
if you need any additional information please don't hesitate to ask.

TIA
Rick W
 
S

Suzanne S. Barnhill

You're using an IF field. This IF field will contain a REF field. Neither of
these fields should be within a form field. As Graham pointed out, the use
of MERGEFIELD is also inappropriate because you're not performing a merge;
the REF field refers to the dropdown field selection.

Although it is possible to nest IF fields, it works just as well to use a
string of IF fields, each using the appropriate text for the TrueText and
leaving the FalseText blank (that is, ""). So the syntax you're looking for
would be something like this:

{ IF { REF Dropdown1 } = "113-25F1" "1" "" } { IF { REF Dropdown1 } =
"131-TAITC" "2" "" }, and so on. I can't quite make out from your code which
values you've attached to specific replies, but you get the idea.


--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
P

Peter Jamieson

Suzanne's and Graham's comments may have solved it for you but..

{IF {=OR ({COMPARE{MERGERFIELD Dropdown1}="113-25F1"},{COMPARE{MERGERFIELD
Dropdown1}= "113-25W4"})}=1 "2" {IF {=OR({COMPARE{MERGERFIELD
Dropdown1}="131-TAITC"}, {COMPARE{MERGEFIELD Dropdown1} ="131-F13-SGI"},
{COMPARE{ MERGEFIELD Dropdown1}="113-25U4"})}=1 "" "1"}"}

1. MERGERFIELD->MERGEFIELD, but as the others have said, you actually need
REF in this case.

2. As presented, the structure of this IF is

{IF{=OR(a,b)}=1 "2" {IF {=OR(c,d,e)}=1 "" "1"}"}

Perhaps you copied by hand and missed out the opening quote for the second
IF

{IF{=OR(a,b)}=1 "2" "{IF {=OR(c,d,e)}=1 "" "1"}"}

3. But more seriously, OR can only have two arguments, so you cannot have
{=OR(c,d,e)}=1.
You can work around that in a couple of ways, e.g.:
{=OR(c,{=OR(d,e)})}=1
or, probably a bit clearer even though you lose the idea that you're really
doing a logical rather than an arithmetic operation
{=c+d+e}>0

(since the result of a COMPARE is going to be 0 or 1)

Further, if you try to fix those OR fields /in situ/ you may find that even
when you get the syntax completely correct, Word still flags various errors,
i.e. it seems to get stuck - in my experience, the simplest thing to do then
is to reconstruct the entire nested field, typically starting with the inner
fields and working outwards.

Peter Jamieson
 
D

Doug Robbins - Word MVP

You will also get this error message if you do not have a space either side
of the operator.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Graham Mayor

As we have established, Mergefields have nothing to do with form fields. The
example you chose to copy was obviously intended for a different task.

You can use conditional fields to insert information in a document directly
based upon the content of a dropdown field, but if you want to insert
information in a text form field (or fields) you need a macro run on exit
from the dropdown field to populate the field(s). The basic code for that is
as follows. This assumes that your Dropdown field is Dropdown1 and the
associated text field you wish to populate is Text1

Sub OnExitDD1()
'fills text field based on content of _
dropdown field

Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
Select Case oFld("Dropdown1").Result

Case Is = "113-25f1"
oFld("Text1").Result = "12345"

Case Is = "113-25F2"
oFld("Text1").Result = "34567"

Case Else
'Do nothing

End Select
End Sub

Add as many case statements as you have drop down choices and associate them
with the required results for Text1 when those choices are made
http://www.gmayor.com/installing_macro.htm

If you need anything more sophisticated, you would need to employ userforms
rather than dropdown forms to gather and distribute your data - you'll find
lots of useful stuff on userforms at Word MVP FAQ - Userforms
http://word.mvps.org/FAQs/Userforms.htm and
http://gregmaxey.mvps.org/word_tips.htm

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

My web site www.gmayor.com

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

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