Results 1 to 13 of 13
  1. #1
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    conditional mail merge with space in field value

    i'm trying to do a conditional mail merge but i get "Error! Unknown op code for conditional" when the value of the field I'm testing has a space embedded in it.

    { IF { MERGEFIELD RoomTypeID } = "2 BD-TP" "TRUE" "FALSE" }

    What is the workaround?

    { IF { MERGEFIELD [RoomTypeID] } = "2 BD-TP" "TRUE" "FALSE" } returns always false, regardless of the content of RoomTypeID (but no error)
    { IF { MERGEFIELD [RoomTypeID] } = [2 BD-TP] "TRUE" "FALSE" } returns always true, regardless of the content of RoomTypeID (but no error)

    Help?

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

    The synatx for the first version is correct - provided all the braces (ie '{ }') are true Word field braces and not merely braces you've typed. True Word field braces can be created via Ctrl-F9, or you could insert the RoomTypeID mergefield from the mergefields toolbar, in which case the field would look like:
    { IF «RoomTypeID» = "2 BD-TP" "TRUE" "FALSE" }
    .
    Last edited by macropod; 2011-05-24 at 05:44.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The braces are from Ctrl-F9, so that's not it. Sometimes the field contains no spaces (ie: 2BD) when that's the case everything works. However when it does have a space, I get the op code error.

    I think it has something to do with how the db app is filling the .dot file fields, it just won't work.

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    If you insert the «RoomTypeID» mergerfield as well as the IF test, what do you get in the output document from the «RoomTypeID» mergerfield when the IF test throws and error?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In a kludgy attempt to bypass evaluating the fields that have spaces in the them, I've written the following, but it's not working either because as soon as RoomTypeID is evaluated it kicks out the error, even if it's false.

    { if { MERGEFIELD RoomTypeID } = "*BD" "LP" { if { MERGEFIELD RoomNo } > 101 "NS" { if { MERGEFIELD RoomNo } = 126 "NS" "TP" } } }

  6. #6
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If I insert it alone (no IF) it works fine (returns 2 BD-TP, for example). I think that's what you're asking - the merge field works fine when simply inserting it's value into the .dot

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

    Try putting double quotes around the mergefield:
    { IF "«RoomTypeID»" = "2 BD-TP" "TRUE" "FALSE" }
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  8. #8
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Same error

  9. #9
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, this is a confirmed bug in the proprietary db app I'm using, but thanks for the help Paul.

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

    I think there's an underlying issue also with the way IF tests work. Since your data fields have numbers, and you're comparing their contents against a value that includes a number (ie "2 BD-TP"), you'll get a false positive any time the data field starts with a '2'. Working around that becomes quite complicated.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  11. #11
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, I found that out the hard way. Working around it:

    { IF { MERGEFIELD RoomTypeID } = "*TP""Twin Peaks" }{ IF { MERGEFIELD RoomTypeID } = "*NS""Twin Peaks (Northstar)"}{ IF { MERGEFIELD RoomTypeID } <> "*TP" { IF
    { MERGEFIELD RoomTypeID } <> "*NS""Lake Placid"}

    Look right?

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

    It appears from what you posted that you have only three room types ("Twin Peaks", "Twin Peaks (Northstar)" & "Lake Placid"). In that case, Try:
    {IF{MERGEFIELD RoomTypeID}= "*TP" "Twin Peaks" {IF{MERGEFIELD RoomTypeID}= "*NS" "Twin Peaks (Northstar)" "Lake Placid"}}
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  13. #13
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There's five (2 BD-TP, 2 BD-NS, 1 BD-NS, 2BD, 1BD) but that makes sense, thanks.

Posting Permissions

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