Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SKIPIF with and/or logic 1

Status
Not open for further replies.

Cozmo2

Technical User
Apr 7, 2006
87
US
I need to have a mail merge that will print only certain activity codes, sometime the activity code has to have a certain dept code. For example:
Run 1
Print all the records with the activity code of "LLL"
Run 2
Print all the records with the activity code of "XXX" and dept code of "22".

The user only want to change the activity code when creating the letters.

Any and all help is appreciated.
 

How about:
Code:
Select Case strUserActivityCode 
    Case "LLL"
        [green]'Where activity code = LLL[/green]
    Case "XXXX"
        [green]'Where activity code = XXX and Dept Code = 22[/green]
    Case "XYZ"
        [green]'When is (Sunny or Claudy) or Friday[/green]
End Select

Have fun.

---- Andy
 
Thanks for the suggestion. I have not used Case statements before. I will have to do research on how! Could I use the case statement to de-dup the file?
 

de-dup the file - I don't know what you mean by that....?

If you already have some code in VBA to accespt user's input - post it here and let's see how we can accomodate different responces in Select Case.

Have fun.

---- Andy
 
Hi Cozmo2,

Try a field coded along the lines of:
{QUOTE{ASK Code "Activity Code to Merge?" \o}{SKIPIF{={IF{MERGEFIELD Activity_Code \* UPPER}= {Code \* UPPER } 0 1}+{IF{MERGEFIELD Activity_Code \* UPPER}= {Code \* UPPER } 0 1}*{IF{MERGEFIELD Dept_Code}= "22" 0 1}}= 1}}

Change the mergefield names 'Activity_Code' & 'Dept_Code' to match your actual field names.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste them from this message.

Andy: SKIPIF refers to a Word field used in mailmerges. Your proposed solution envisages using vba and has no relation to a SKIPIF field.


Cheers
[MS MVP - Word]
 
Thanks macropod for the response. I had to remove the "Quote" piece because I kept getting an "You cannot insert data, next, nextif or skipif fields inside other fields" error.

Now I want to change the statement to pull all the records of a certain activity_cod but if that activity_cod = "LDL" and the dept_cod = "TB" skip the record. Any thoughts?
Also, what does the + and the * represent in the statement you provided?

Here is the statement I am using:

{ASK Code "Activity Code to Merge?" \o}{SKIPIF{={IF{MERGEFIELD activity_cod \* UPPER}= {Code \* UPPER } 0 1}+{IF{MERGEFIELD activity_cod \* UPPER} <> "LDL" 0 1}*{IF{MERGEFIELD dept_cod}= "TB" 0 1}}= 1}

It gives all the records for the activity requested in the Ask and all the records with the activity code of "LDL" except the records with a dept_cod of "TB". I do not want the "LDL" records unless this activity_cod is the response to the ASK statement.
Thanks for your help.
 
Hi Cozmo2,

So how many possible variations do you have? You previously mentioned only two. Now there are at least three.

. And how flexible does the ability to vary these need to be? The answer on how do implement the field code very much depends on how the answers to these questions.

For example, the code one might use to give the user full control over which activities and depts to include or exclude would be very different from that used for what you've described so far.

The + and the * represent logical OR and AND expressions, respectively. These are used in conjunction with the 1/0 values returned by the IF tests to perform a calculation.

Note too that, as I'm travelling with only intermittent & slow internet access, I can't guarantee a quick reply.


Cheers
[MS MVP - Word]
 
The user needs to control which activity_cod to select/print. Only one activity_cod prints at a time.
If the activity_cod “LDL” is selected we want to skip all records that have a dept_cod of “TB”
If the activity_cod “LAL” is selected we want to skip all records that have an “agency_txt” = “John Jones”
For any other activity_cod all records with that activity_cod are to be printed.

If there is more than one record for a student we only want to print once.

I think these are all the criteria (for now!).
Thanks for your help.
 
I was able to get the code to work the way it needs to by removing the OR logic!

However, I am still having problems when a student is in the file twice, two letters are printed and I only need one.
Thanks for any help.
 
However, I am still having problems when a student is in the file twice
Should the student be in the file twice?
If not, run a query that removes duplicate entries.
Or, create a query that lists students once and base your code on the query instead of a table.


Randy
 

Please disregard my response.
I thought I was in an Access forum. [blush]


Randy
 
Hi Cozmo2,

Yoy really should clean up the data first. After all, if there are differences in detail between the two records, how is Word supposed to know which one is correct?

If you really want Word to eliminate duplicate records, you could tell it to execute the merge in a sorted record sequence (eg by Student ID), then use a combination of bookmarking and a SKIPIF field to skip the current record if it is for the same student as the previous record. You'd also need to add exception logic for handling the first record, and so on.


Cheers
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top