Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Delete a line if bookmark is empty

    We merge a lot of documents from our SQL database using the MS Word bookmarks.

    A new requirement is to add the "Division" name to the address block. However, not all organisation use/have divisions so we wish to delete the line that contains the ClientDivision bookmark if it is empty.

    I know how to do this using the MailMerge function.

    Any ideas?
    cheers

    Phil Carter

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Any ideas on how to do this using VBA or mail merges?

    If you are doing it with code, when the Division field is non empty, insert the Division text followed by vbCr into the bookmark. Otherwise leave the bookmark empty.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by bonriki View Post
    A new requirement is to add the "Division" name to the address block. However, not all organisation use/have divisions so we wish to delete the line that contains the ClientDivision bookmark if it is empty.
    If this is a true mailmerge, you can suppress the "Division" line by using individual mergefields instead of the AddressBlock field.

    To suppress the empty "Division" line:
    • delete the line/paragraph break on the line before the «Division» mergefield;
    • select the «Division» mergefield and press Shift-F9. You should see { MERGEFIELD Division };
    • add the following switch to the field code by adding the \b switch, thus - { MERGEFIELD Division \b "¶"} or { MERGEFIELD Division \b "↵"}, where the ↵ and ¶ represent real line/paragraph breaks (note that you'll get a line/paragraph break in the mergefield);
    • press F9 to update the field; then
    • run your mailmerge.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. The Following 2 Users Say Thank You to macropod For This Useful Post:

    bonriki (2013-10-17),Charles Kenyon (2013-10-17)

  5. #4
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts
    Paul thanks for that
    Unfortunately this is not a straight MS Word merge and we do not use mergefields. Rather it is an extraction of data from our SQL database and parsing it to named bookmarks in the Word document. The code used for extracting the data is written in XML and typically looks like this;

    <content type="expression" id="ClientDivision" locationtype="bookmark" locationname="ClientDivision" function="insertafter" value="(AU.Program.minOrganization.Division)" object="objAUJob" />
    cheers

    Phil Carter

  6. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Phil

    You haven't shown us how your code takes that xml information to place it onto the page. That is where the code needs to be altered. If you can show us that part of the puzzle we can suggest a way to handle it.

    If you can't see the vba code of how the xml gets placed into the document then maybe you need a post-processing bit of code that does something along the lines of the following aircode

    Code:
    If ActiveDocument.Bookmarks("ClientDivision").Range.Text = "" then ActiveDocument.Bookmarks("ClientDivision").Range.Paragraphs(1).Delete
    Last edited by Andrew Lockton; 2013-10-17 at 16:40.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    bonriki (2013-10-17)

Posting Permissions

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