Results 1 to 13 of 13
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Empty Document Variables (Word 2000)

    I've encountered a problem using document variables that I'm wanting a workaround for. I often use docvars referenced in formfields, in preference to bookmarks, and use a VBA userform as the UI to Get/ Set these variables. The problem (that's just recently become apparent) is that docvars are "nuked" from the Variables Collection if they become an empty string. This contrasts to the behaviour (and hence usefulness/ flexibility) of bookmarks, which can hold an empty string without being ousted from the Bookmarks Collection.

    There are many instances where I'd like to set a docvar to an empty string (initial blank fields in a new document and its userform, optional information the user may not need, ...) and I'd like a method of retaining a static collection of variables - empty and non-empty alike - without the need to continually "monitor" what's still there and what might have been knocked out. I've written/ lifted/ used various routines & code wrappers as "failsafe" set & get methods, but it's become pretty cumbersome to use these in all situations e.g. display a textbox that contains an empty docvar. I'm hoping for an easier way out of this.

    Alan

  2. #2
    New Lounger
    Join Date
    Sep 2003
    Location
    Melbourne, Victoria, Austria
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Empty Document Variables (Word 2000)

    Alan,

    The attached word template should solve your problem, have a look at the code behind the "Finish" button you will see & " " , this adds a space to the variable..

    When you add the variable into a document make sure there is not spacing. Also the attachment was originally used to explain using variable in lieu of Bookmarks., so I hope you don't mind that I have not changed it. I am sure you will work it out.

    Regards,

    <img src=/S/aussie.gif border=0 alt=aussie width=21 height=22>

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

    Re: Empty Document Variables (Word 2000)

    Thanks John. I've played with token characters before, including spaces, and found them to be problematic for various reasons. I'll be interested in your approach though.
    <hr>I am sure you will work it out.<hr>
    I'll have to be able to see it first <img src=/S/grin.gif border=0 alt=grin width=15 height=15>.

    Alan

  4. #4
    New Lounger
    Join Date
    Sep 2003
    Location
    Melbourne, Victoria, Austria
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Empty Document Variables (Word 2000)

    Alan,

    I have used them and have not had any problems (as yet) , I dont think that my attachment worked with my first post , so here it is again.

    Regards,

    <img src=/S/aussie.gif border=0 alt=aussie width=21 height=22>
    Attached Files Attached Files

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

    Re: Empty Document Variables (Word 2000)

    Hi John

    Looks fine for the kind of "block" layout you have, where the extra whitespace isn't a problem I presume. This is, however a (the) problem for the kind of inline docvar values I want to display. It has triggered some thoughts though - maybe using an IF field to display nothing if the docvar is only a "space". Thanks for the ideas.

    Alan

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

    Re: Empty Document Variables (Word 2000)

    Thanks John. Your example inspired me <img src=/S/grin.gif border=0 alt=grin width=15 height=15>. I have used the single space "placeholder" as you have done, but used the following concoction in the document body:

    { IF { DOCVARIABLE MyDocVar } = " " "" { DOCVARIABLE MyDocVar }}

    This means that a docvar that's meant to be nothing will actually appear as nothing in the body text.
    I used trim(MyDocVar) as the .Text property for userform text, and all appears sweet.

    cheers

    Alan

  7. #7
    New Lounger
    Join Date
    Sep 2003
    Location
    Melbourne, Victoria, Austria
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Empty Document Variables (Word 2000)

    <P ID="edit" class=small>(Edited by Phil Rabichow on 21-Jan-04 11:36. to remove the extra returns that created a large amount of white space)</P>Alan,

    As I said that template was only an example I did for someone else (in New Zealand). I have used it (variables) in "normal" flowing text document. What you have to do is NO leave a space between the last word before the variable and next word after the variable. I only use the &" " on fields that may not require an answer.

    Hope this helps,

    Regards,

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

    Re: Empty Document Variables (Word 2000)

    Hi Alan

    I was really excited when I found this post, but I have to admit I am having trouble working out how you insert this Field { IF { DOCVARIABLE MyDocVar } = " " "" { DOCVARIABLE MyDocVar }} into my document. Can you give me step by step instructions Please>>>>>>>>>>>>> <img src=/S/blush.gif border=0 alt=blush width=15 height=15>.

    Kerry

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Empty Document Variables (Word 2000)

    Hi Kerry:
    To insert the field:
    { IF { DOCVARIABLE MyDocVar } = " " "" { DOCVARIABLE MyDocVar }}, do this:
    1. Press Ctrl+F9 to insert field braces.
    2. Type IF & a space.
    3. Press Ctrl+F9 & type DocVariable MyDocVar
    4. Right arrow 3 spaces to where the equal sign is above & type
    "sp"sp""sp
    where sp stands for a space.
    5. Select & copy the { DOCVARIABLE MyDocVar } field to where you next see it above.
    6. Press F9 to update the field.

    For general instructions on filling out IF fields & how they work, see <post#=273185>post 273185</post#>.
    Hope this helps,

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

    Re: Empty Document Variables (Word 2000)

    Hi Kerry

    Yep, pretty much like Phil says. I'd just add my <img src=/S/2cents.gif border=0 alt=2cents width=15 height=15>.

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

    Re: Empty Document Variables (Word 2000)

    Thanks Phil, I managed to get this to work. As Alan suggests I could have simply cut and paste, but I wanted to know how to actually do it in the first place. It all part of the learning experience.

    Kerry

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

    Re: Empty Document Variables (Word 2000)

    Alan when you say bookmarks cant be blasted away, what do you mean? Do you mean deleted by the user? I wouldnt have thought this could happen when using a template. Can you elaborate a bit more on your "BTW".

    Kerry

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

    Re: Empty Document Variables (Word 2000)

    Kerry,

    Again my slang terminology is getting me into trouble. What I was getting at (in the thread as a whole) is that if a docvar is set to an empty string, for instance via a textbox entry, then that variable is deleted (blasted away) from the Variables Collection. This is normal for a collection, when a variant member is set to Null. But, in my opinion, this is not appropriate behaviour for this particular collection, since the Variables Collection represents a non-volatile collection of data which is specifically attached to its container document, much like bookmarks are. In this sense it merits its own special "structure" IMO.

    Bookmarks are also contained in a collection - the Bookmarks Collection, but each bookmark is an object, rather than just a simple (variant) variable. Among other things, a bookmark object contains a .Range object (which in turn has a .Text property). So, by contrast, setting the .Range.Text property to an empty string does not (can not) set the bookmark object to "Null", and therefore doesn't destroy the bookmark.

    But bookmarks do have more vulnerability to user fiddling. Protected forms etc. can deter a user from deleting a bookmark, but they are still "exposed" at the user interface, and a determined user could still add/ modify/ delete a bookmark in a way that was not intended. This is where docvars come to the fore - they can only be manipulated via VBA code, so can be shielded pretty effectively from the user. So what I was really trying to say is that I'm disappointed that the Document Variable collection wasn't more like the Bookmarks Collection in terms of being able to have "placeholders" that might contain empty strings. Hope that explains it.

    Alan

Posting Permissions

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