Next If

C

Chris Stammers

Hello,

I am trying to set up a document and I need it to ignore a record with a
given criteria. I have used 'Skip If' before however this statement generates
lots of error messages within our document generation system and I am trying
to avoid that. How does 'Next If' differ from 'Skip If' and can I use more
than one 'Next If' statement in a document? I have set the document up with
the following:

«Next If {FIELD1} <> 2» «Next If {FIELD2} <> 1» «Next If {FIELD1} <> B»

Do you foresee any problems with that? I am using Windows XP and Word 2000
from Office 2000 Premium

Thanks,
Chris
 
P

Peter Jamieson

<<Next if>> has some similar constraints to <<Skip if>>, e.g. you can't use
it in certain places such as text boxes.

However, the effect of <<next if>> is quite literal, i.e. if the condition
is true, Word will move to the next data source record and continue
processing the current "copy" of the Mail Merge Main Document. If the
condition is false, Word takes no action. So...
«Next If {FIELD1} <> 2» «Next If {FIELD2} <> 1» «Next If {FIELD1} <> B»

....if you're trying to use that to move 3 records if field1 is "C" and
field2 is 50, that should work. But if you're trying to move 1 record if
(field1 is not 2) or (field2 is not 1) or (field1 is not B) then you need to
put all the conditions inside a single <<Next if>>, which you could do using
e.g.

{ NEXTIF { ={ COMPARE { MERGEFIELD FIELD1 } <> 2 }+{ COMPARE { MERGEFIELD
FIELD2 } <> 1 }+{ COMPARE { MERGEFIELD FIELD1 } <> "B" } } <> 0 }

(Or something like that...)

Peter Jamieson
 
C

Chris Stammers

Thanks Peter. Apologies if I sound thick here - do I need to manually
construct that statement? It's just that it is my understanding that it won't
work if you do and the Next If statement doesn't have the facility to expand
or add in the way. Or am I totally missing the point?

Thanks.
Regards,
Chris
 
P

Peter Jamieson

do I need to manually
construct that statement?

Yes, you basically start with ctrl-F9 to insert each pair of the special
field braces {} and type everything else. You could do it in VBA also.
It's just that it is my understanding that it won't
work if you do

Not sure what you mean here - are you saying that { NEXTIF } fields will
only work if you construct them using the Next If dropdown entry?
and the Next If statement doesn't have the facility to expand
or add in the way.

...or here!

Peter Jamieson
 
C

Chris Stammers

One more question - will the NEXTIF function select the next record even if
it doesn't meet the criteria? The reason I ask is that when I constructed the
string, the document produced however there were records included that
shouldn't have been. Also, what is the function of the <> 0 inside the last
bracket?

Thanks,
Chris
 
P

Peter Jamieson

One more question - will the NEXTIF function select the next record even
if
it doesn't meet the criteria?

Yes. All NEXTIF does is tell Word to move to the next record if the criteria
match. Word then processes the remainder of the Mail Merge Main Document
starting from that document.

This is wht I meant when I said that "the effect of <<next if>> is quite
literal". It doesn't provide a mechanism to filter all records that match
the criteria until you get to the next one that does not. In theory, SKIP IF
kind of does that, but also has its limitations. In short, there is at least
one field missing from the language and it's probably something like { NEXT
WHILE }

Typically to exclude all records that meet certain criteria, you need to do
it in the data source and/or the query that drives the merge. But that's
actually logically different from what a { NEXT WHILE } would give you.
Also, what is the function of the <> 0 inside the last
bracket?

COMPARE returns 0 if the comparison fails and 1 if the comparison succeeds.

So the { =compare+compare+compare } field returns 0 only if all the
comparisons fail. If one or more succeed you get a number between 1 and 3.

So if you want to NEXTIF only if one or more comparisons succeed, you want
{ =compare+compare+compare } to be non-zero (or > 0, if you want).

Peter Jamieson
 
C

Chris Stammers

Thanks again Peter. I have kept your query string, including the <> 0 at the
end, but substituted the NEXTIF for SKIPIF. This seems to have worked fine.

Thanks again for your guidance.
 
A

Andrew Bosanquet

I am probably trying to mimic the NEXTWHILE (that does not exist).

I want to include data from the next record(s) while one field stays the same. For instance, I want three documents from the following data:

Field1 / Field2 / Field3
1 / A / a
1 / B / b
3 / C / c
7 / D / d
7 / E / e
7 / F / f
7 / G / g

Documents to be headed 1, 3, and 7.
Document1 to have a table of A/a, B/b.
Document3 to have a table of C/c.
Document7 to have a table of D/d, E/e, F/f, G/g.

Documents and tables are all sorted – I just cannot get the logic right.

Can I COMPARE { MERGEFIELD FIELD1 } with FIELD1 in the *next* record?

Many thanks

Andrew


EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
D

Doug Robbins - Word MVP

Sounds like you are probably trying to perform a "multiple items per
condition (=key field)" mailmerge which Word does not really have the
ability to do:

See the "Group Multiple items for a single condition" item on fellow MVP
Cindy Meister's website at

http://homepage.swissonline.ch/cindymeister/mergfaq1.htm#DBPic


Or take a look at the following Knowledge Base Article

http://support.microsoft.com/default.aspx?scid=kb;en-us;211303

or at:

http://cornell.veplan.net/article.aspx?&a=3815


--
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
 
J

JimmyMD

What I need to do is nextif only when a field in the next row is equal to the
same field in the current row. IE: nextif mmfield1 = mmfield1 I coded that
but it continues to give me the next row anyway. Can I do that?
 
D

Doug Robbins - Word MVP

Same answer.

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

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