Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Mysterious Space in Variable (Word 97)

    I am placing the code below into my document for fields on my userform. For some reason I am unable to work out, there is a space after the variable when the Userform is updated. For example if the Offender is Fred Bloggs it will show as

    Fred Bloggs . Note the space after the s.

    I hope this makes sense.

    Kerry

    { IF { DOCVARIABLE varOffenderName } = " " "" { DOCVARIABLE varOffenderName}}

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

    Re: Mysterious Space in Variable (Word 97)

    Are you absolutely sure that the value of the document variable itself doesn't contain a trailing space? I mean "Fred Bloggs " instead of "Fred Bloggs". Field code like yours doesn't display a trailing space on my system (Word 2002 SP-2, admittedly.)

    Added later
    You can test this as follows:
    - Activate the Visual Basic Editor.
    - Activate the Immediate window (Ctrl+G.)
    - Type ? "." & ActiveDocument.Variables("varOffenderName") & "." and press Enter.
    - Check if there is a space before the final period.

  3. #3
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Mysterious Space in Variable (Word 97)

    I got this result -

    ? "." & ActiveDocument.Variables("varOffenderName") & "."
    . .

    This is how the variable is set up.
    .Variables("varOffenderName").Value = tbxOffenderName & " " ------- should there be no space between the two " "s??

    Kerry


    Edited
    Yes that was it. I took out the space between the " "s and it worked. Thanks Hans

    EDITED AGAIN!

    That didnt work - I needed that space in there to allow and empty variable. - Now I am stumped. Help.

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mysterious Space in Variable (Word 97)

    Kerry

    This comes back to my pet hate with docvars - that they can't hold an empty string. This is what I whinged about at length in <post#=333395>post 333395</post#> and others. The idea of the single blank space, as I've adapted it, is to use it as a placeholder to prevent the docvar from becoming empty, and consequently disappearing. The kind of code you'll need, to avoid stray spaces, is something like this:

    If tbxOffenderName = "" then
    .Variables("varOffenderName").Value = " "
    else
    .Variables("varOffenderName").Value = tbxOffenderName
    End If

    You'll also need to arrange to not show a solitary space in the textbox when you load your docvars into the userform. Something like this:

    If .Variables("varOffenderName").Value = " " then
    tbxOffenderName = ""
    else
    tbxOffenderName = .Variables("varOffenderName").Value
    End If

    There are other ways to get round the docvar annoyance. One is to always use the .Add method to change a value, but this is also a pain since if varOffenderName exists you have to delete it before adding it, and if it doesn't exist and you try to delete it you generate an error. So the implementation is a bit messy.

    <img src=/S/ranton.gif border=0 alt=ranton width=66 height=37> This whole issue of docvars being treated just the same as any "volatile" collection is a pet peeve of mine, as you may gathered <img src=/S/grin.gif border=0 alt=grin width=15 height=15>. They should be given the same status as bookmarks - get your rear into gear MS! <img src=/S/rantoff.gif border=0 alt=rantoff width=66 height=37>

    Alan

  5. #5
    4 Star Lounger
    Join Date
    Apr 2002
    Location
    Northern Territory, Australia
    Posts
    471
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Re: Mysterious Space in Variable (Word 97)

    Alan I hear what you are saying, but believe me, other than the space issue, the whole thing works beautifully for me. If it is going to be a big deal to get rid of that space, then I will leave the darn thing there. Other than where there is an apostrophe after the offender's name it causes no big problem.

    Kerry

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

    Re: Mysterious Space in Variable (Word 97)

    Hi Kerry,

    In that case, you might not need the IF test. Using just:
    {DOCVARIABLE varOffenderName}
    might do but, depending on how your document is set up, you may need something like:
    {IF{DOCVARIABLE varOffenderName}= " " " " "{DOCVARIABLE varOffenderName} "}
    (note the space after the 2nd instance of {DOCVARIABLE varOffenderName}), or
    {IF{DOCVARIABLE varOffenderName}= " " " " " {DOCVARIABLE varOffenderName}"}
    (note the space before the 2nd instance of {DOCVARIABLE varOffenderName}).

    Cheers
    PS: where you need an aposteophe, you could use something like:
    {IF{DOCVARIABLE varOffenderName}= " " " " " {DOCVARIABLE varOffenderName}'s"}
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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