Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jun 2008
    Location
    Baltimore, Maryland, USA
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Either / Or Code (Word 2003)

    Good afternoon. My apologies for "double posting" I also posted this in the VB/VBA section, but later thought tat this may be the more appropriate place to run it.

    I am attempting to construct a macro (rather, modify an existing one) that uses field codes from a separate program, and would prevent the user of the program from being able to print a document without first entering required characters in the referenced program field(s). I have discovered that if a macro with field Codes is installed in a Word document, Word will not allow the user to print the document unless the fields corresponding to the codes have recognizable data entered in them If a user attempts to do so, an error message (Syntax error) page prints instead. I can use this behavior to my advantage so as to ensure proper document preparation in an automated way.

    The problem I am encountering is in accommodating a contingency. I need to write the code such that more than one possible character entry will be interpreted as "0". I have already written a macro (containing bookmarks for the field codes) that effectively facilitates this interpretation for one character. The missing ingredient in my recipe is the proper representation of the concept of "OR" - i.e. - "If FIELD CODE #5 = either "X' OR 'Y', then interpret FIELD CODE # 5 as '0'."

    Here is the original version of the bookmark, which works as intended (for one specific character - "X"): { IF <<Point Field 9926>> = “X” “0” “<<Point Field 9926>>” }

    Here us what I need, effectively: { IF <<Point Field 9926>> = “X” OR "Y" “0” “<<Point Field 9926>>” }

    The result of using the second bookmark shown above is the generation of a Syntax Error, which occurs when either an "x" or a "Y" is entered in the screen field (9926). I tried adding parentheses as thus - (“X” OR "Y" “0”) - but that did not solve the problem.

    I have attached a Word document that contains each of the entire macros, with the formatting intact, which allows for modification to the code. It also provides more details about the contextual application, as well as the actyal variable in the macro.

    Can anyone tell me the correct way to represent the "'X' OR 'Y'" part of the code? Or is it a matter of proper placement of parentheses?

    Also - If there is a better way to ensure screen data entry - a way to "force" a user to enter data in required fields in order to print a document, please let me know. The technique described above simply exploits an incidental performance characteristic of Word. There may be a feature of Word that was specifically designed to achieve that effect, perhaps in a better way.

    Any help would be greatly appreciated. Thank you very much.

    KO
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Either / Or Code (Word 2003)

    Welcome to Woody's Lounge!

    Your question has nothing to do with VBA - field codes are not the same as VBA macros.

    If you want to check whether a merge field equals "x" or "X", you can format the field as upper case and compare it to "X":

    { IF { MERGEFIELD PNT_9926 * Upper } = "X" "0" "{ MERGEFIELD PNT_9926 }" }

    If you want to check whether a merge field equals one of two different values, you can use the OR function combined with the COMPARE function:

    { IF { =OR({ COMPARE "{ MERGEFIELD PNT_9926 }" = "X" }, { COMPARE "{ MERGEFIELD PNT_9926 }" = "Y" }) = 1 "0" "{ MERGEFIELD PNT_9926 }" }

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Either / Or Code (Word 2003)

    <P ID="edit" class=small>(Edited by macropod on 20-Jun-08 10:39. Additional info re ignoring case)</P>hi KO.

    Welcome to the Lounge.

    I take it you're working with a mailmerge.

    One solution to your problem is to use a nested IF test, as in:
    {IF«Point Field 9926»= X 0 {IF«Point Field 9926»= Y 0 «Point Field 9926»}}
    Note that you don't need to use the double quotes for expressions that are a single character or another field.

    To handle upper & lower case entries, you can do away with the OR test. If you select the first mergefield and expand its code via Shift-F9, you can add an upper-case picture switch to the field (* Upper) and use:
    {IF{MERGEFIELD Point Field 9926 * Upper}= X 0 «Point Field 9926»}

    Alternatively, check out my Word Field Maths 'tutorial' in <post#=365442>post 365442</post#> for a more elaborate solution, under the heading 'Testing Or Returning Text Strings With Logical Functions In Bookmarks'.

    Oh, and BTW, you're not working with macros, but with field coding - quite a different beast.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    Star Lounger
    Join Date
    Jun 2008
    Location
    Baltimore, Maryland, USA
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Either / Or Code (Word 2003)

    Paul -

    Thank you for your suggestions. Both of the augmentations you provided did exactly what I was seeking. Sorry for my terminological confusion. I am indeed working with mailmerge field coding. I have learned through reverse engineering and trial and errror, so the gaps in my knowledge base are many and profound. I would never have stumbled upon the solutions you posted, so your help is greatly appreciated. I will experiment with these ideas, and see if I can apply them to achieve my ultimate goal.

    That coding tutorial you put together is fantastic. What a great resource. That might have saved me some time as I was grinding my way through various fee and payment calculation equations/ (I was surprised at the difficulty I encountered constructing a mortgage payment equation. "To the power of" proved to be a crucial component.)

    Thanks again.

    KO

  5. #5
    Star Lounger
    Join Date
    Jun 2008
    Location
    Baltimore, Maryland, USA
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Either / Or Code (Word 2003)

    Hans -

    Thanks for your help. I have been applying the modifications you suggested. I was able to format the upper/lower case code effectively right away. I am having some trouble with the two different values comparison equation. I must be misplacing a character. I'll keep working with it.

    I will experiment with the ideas you and Paul provided, and see if I can use them to format my "forced data entry" equation.. I may need to impose on the group again in order to make it work.

    This forum is a great thing, especially for confused people such as myself. I didn't realize that a resource of this type existed. Thank you for administering it, and for your assistance with my questions.

    KO

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •