Consulting

Results 1 to 8 of 8

Thread: Help with "IF...Then" within a Word document

  1. #1
    VBAX Newbie
    Joined
    Apr 2010
    Posts
    5
    Location

    Help with "IF...Then" within a Word document

    Hi everyone, I'm kinda stuck on something that seems like it should be simple enough, but it's not working for me. I have these documents that use bookmarks that are automatically filled in with a doctor's name and a signature line above the bookmark. I'd like to have the signature line only appear if the bookmark is filled in. So it'd be something like this

    (I'm using QuickParts->Fields->If)

    {IF cosignature = (this is where I’m stuck) “_____________” “ “\* MERGEFORMAT}

    Is it something simple like - If cosignature <> NULL or something? It doesn't seem to want to work for me. Any ideas here would be great!!!

    Thanks!!!

  2. #2
    VBAX Newbie
    Joined
    Apr 2010
    Posts
    5
    Location
    I forgot to specify, but I'm using Word 2007, in case that matters.

    Also, the document looks kinda like this right now...


    ____________________
    [cosignature bookmark]


    And after then end user acts on it, it looks like this...

    ____________________
    John Smith, M.D.



    Thanks again!!!

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi John,

    You could use something like:
    {IF cosignature <> "" "_____________"}

    I assume the 'cosignature' bookmark is in a formfield. If so, make sure the formfield's 'calculate on exit' property is set and that you have whatever the default value for the formfield is between the first pair of double quotes. Usually, that's 5 spaces, for which your field code would become:
    {IF cosignature <> " " "_____________"}

    Note: You don't need the '\* MERGEFORMAT' switch.

    FWIW, you skip the can skip the QuickParts->Fields->If route and hand-code the field by pressing Ctrl-F9, then inserting the required code between the field braces. It's much easier to nest fields this way.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    Another option would be to encapsulate the line and the title inside the bookmark and use the font's hidden property.

    [vba]ActiveDocument.Bookmarks("DrSig").Range.Font.Hidden = False[/vba]

    David


  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Please clarify.

    "I'd like to have the signature line only appear if the bookmark is filled in. "

    That does not match what you later state.

    ____________________
    [cosignature bookmark]


    THAT seems like the line is there to start with. In case, how about this? Demo attached. You do not state exactly how information is to be passed to the bookmark. I used a userform. Click "Show Userform" on the top toolbar. If you select nothing (no text),nothing happens. If you select an item from the list, and click OK, the text is inserted, and the paragraph above becomes lined.

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Version2: it becomes a toggle.

    Click OK with an item, the bookmark has the text, the paragraph above is lined.

    Click OK with nothing, if the bookmark currently has text it is removed; the paragraph above, if lined, becomes unlined.

  7. #7
    VBAX Newbie
    Joined
    Apr 2010
    Posts
    5
    Location
    Thanks for the help so far. I still can't get it working correctly. To answer some of the questions here... the bookmarks are being populated by an xml file.

    Macropod, the solution you posted is along the lines of what I need, but for some reason, whether the bookmark is filled in or not, I still get the signature line. Any ideas?

    Thanks so much for the help everyone, I really appreciate it!!

  8. #8
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "Thanks for the help so far. I still can't get it working correctly."

    And what does that actually mean. I just tested the file I posted and it works precisely, exactly, as you state you want.

    "filled in with a doctor's name and a signature line above the bookmark. I'd like to have the signature line only appear if the bookmark is filled in. "

    It fills in the name, and a line above if a name is selected. if a name is NOT selected, there is no name, or line above.

    EXACTLY as you state you want. It does not help at all when you state it is not "working correctly". That does not tell us anything. What is not working correctly? What is happening that is not correct?

Posting Permissions

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