Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Zero length text field? (WinNT/Word97)

    I am working on a template that is going to be a several page document in the form of a letter, with numerous fields of one sort or another to add the variable information.

    One of the options is going to be to have a sentence included or not - and if it's not, the text field needs to be zero length, ie there will not be a gap in the text. At the moment even if the field is empty it shows as a space the equivalent of about 5 or 6 characters long!

    Is there a way to make it zero length? Or could I use an exit macro to say "if blank, delete this field", and if so, how do I refer to the field, because I can't find anything that I can use as a name to say "go to the field called ..." - it has a bookmark name attached to it, but again I can't find how to refer to it! The other thing I thought of was an entry macro for the next field saying "if prev field is blank, remove it" but again I came up against the same problems!

    Unfortunately this is being produced in response to regulatory requirements so I have absolutely no leeway with regard to laying it out differently (eg I would have made it the end of a para, so some blank space wouldn't matter!) and it *has* to be protected when complete (no user editing permitted at all outside the variable info), hence using form fields for said variable info. <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>
    __________________________________________________

    Edited to add: I have just realised that I am going to need to calculate using some of the number fields, too - so again, I need to be able to refer to them! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    __________________________________________________

    Any help would be gratefully appreciated.
    Beryl M


  2. #2
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Hi Beryl,

    It's not possible to make a FormField (FF) zero-length. As you experienced, it will expand to the default 5-character length if you place an empty string in it. I encountered the same problem and use this work-around: place the FF between two words without spaces to the left and right. If the FF should be "empty" then put one space in the FF. If the FF should contain text, then place that text between two extra spaces in the FF. Works like a charm for me!

    FFshave a name, so you can use that to refer to the FF. In that regard they act like a Bookmark:

    If ActiveDocument.Bookmarks.Exist("MyFF") Then
    Selection.GoTo What:=wdGotoBookmark, Name:="MyFF"
    End If

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Thanks, Jan - the info re referring should be great.

    I'm not sure how I'll deal with the zero length bit, because the particular one I'm looking at that prompted the post is the first sentence in a paragraph - and hence won't want even that one space! Still something that removes a formfield that's empty should work now I know how to refer to it ...

    I'll post my solution when I have it (assuming I'm able to do it with HansV on holiday for the next three weeks! <img src=/S/weep.gif border=0 alt=weep width=21 height=16> <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>)
    Beryl M


  4. #4
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Aha. Then you could put somthing like this in the exit macro of that FF, or in the entry macro of the next FF:

    If Trim(ActiveDocument.FormFields("MyFF").Result) = "" Then
    ActiveDocument.FormFields("MyFF").Delete
    End If

    Of course you have to temporarily lift protection to do this.
    Another thought: what should happen if the user made a mistake and realises that to late?

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Argghh! Okay, so we're back to square one - how DO we get an empty formfield to display zero-length?!!

    <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    Beryl M


  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Hey, just thought of something, variation on your solution - could I set a 'run on entry' macro to bring up a userform with two options, 'display this sentence' Yes or No, and have the contents of the formfield be the sentence including the first word of the next sentence if Yes, or just the first word of the next sentence if no?!!

    Edited to add: It would have to be via a userform 'cos if I let them do it direct they'd be bound to delete the extra word too!

    Hah! <img src=/S/joy.gif border=0 alt=joy width=23 height=23> <img src=/S/groovin.gif border=0 alt=groovin width=21 height=21> How's that for lateral thinking?! <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>
    Beryl M


  7. #7
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Good thinking! <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

    But it's possible to do this without a userform; I do it all the time. In the line immediately above the sentence with the FF at the beginning, put some instructional text ("Make a choice:"), followed by a dropdown-FF containing just Yes and No. Attach an exit macro to this dropdown that fills the text-FF with the appropriate text as you mentioned in your last post. Then select that whole sentence without the paragraph mark and make that hidden text. (I always use red, hidden, 8 point text, so that it stands out in the doc.) Of course you have to (programmatically) turn showing hidden text on: ActiveWindow.View.ShowHiddenText = True.
    This way you let your users make a choice without reverting to a userform for this relatively small task. I don't know about your users, but on my end, they don't like templates with a mixture of FFs and userforms.

  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Good idea. I don't know what my users would say to the mixture; I've never tried to give them one before! We usually use userforms, but for this particular template the non-editable text had to be protected whilst leaving them the option of changing their variable text if they got it wrong, and this was the best I could think of!

    I'll experiment and see what happens ... hang on ... flash of brilliance and rush of something unmentionable to the brain before she even posts her answer this time ... That's it!!!
    <img src=/S/lightbulb.gif border=0 alt=lightbulb width=15 height=15> <img src=/S/bingo.gif border=0 alt=bingo width=15 height=22>

    Why bother with the extra text etc?! I just realised - all it needs is an exit macro that formats just the formfield itself as hidden text if it's empty!!

    <img src=/S/thewave.gif border=0 alt=thewave width=225 height=33> <img src=/S/thewave.gif border=0 alt=thewave width=225 height=33>

    And we've done it -<span style="background-color: #FFFF00; color: #000000; font-weight: bold"><font color=red> there IS a way to have a zero-length formfield!! </font color=red></span hi>

    <img src=/S/thewave.gif border=0 alt=thewave width=225 height=33> <img src=/S/thewave.gif border=0 alt=thewave width=225 height=33>


    I don't know if it's one/both of us that's brilliant or if we just make a good team - but we got it!! Now I can get on with the damn thing - and I hope you have a wonderful weekend - you deserve it!

    Many thanks!
    Beryl M


  9. #9
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30> Brilliant thought!
    And we sure make a good team. Too bad we can't have a <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> together. That's just what I need right now!
    Have a wonderful weekend yourself too.

  10. #10
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    What's more, you don't even need to lift the protection to do it! You can't format the font to hidden on the field itself (fields don't seem to have a font property), but if you do this ...

    If Trim(ActiveDocument.FormFields("MyFF").Result) = "" Then
    ActiveDocument.FormFields("MyFF").Select
    Selection.Font.Hidden = True
    End If

    ... it does exactly the same thing. Problem solved!

    Tell you what, I'll have a <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> for you this eve! (I'm certainly going to need one by the time I get home!)
    Beryl M


  11. #11
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Glad you solved it Beryl. <img src=/S/yep.gif border=0 alt=yep width=15 height=15>
    One last thought: if the FF is at the end of a paragraph, be very careful that the end-of-paragraph marker is not icluded in the selection. Word tends to include it often. If that is the case, then the next line will be placed right after the previous paragraph when you print the doc. I've experienced that a few times myself...

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

    Re: Zero length text field? (WinNT/Word97)

    Hi Beryl:
    That's an interesting solution. When I use your code in the VBE & step through it, it gives me a message that the "method or property is not available because it refers to a protected area of the document". Yet pressing F5 works. Do you know why?

    Also, I wanted to see if you could change the font to not be hidden once it was. I tried:

    Else: ActiveDocument.FormFields("MyFF").Select
    Selection.Font.Hidden = False

    but this also gave the message & didn't work. What should be changed for this to work?
    Thanks,

  13. #13
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Unfortunately I only just picked this up and I'm at home so I can't try it at the moment, but it still worked when I left the office this afternoon! I can't see anything obvious in what you say, and the only possibilities that come to mind are (1) are you using Word 97? Maybe it got tied down more tightly in later versions? - (2) it does fall over if anything at all other than the field is selected, as only the form field itself is available when the doc is protected, and (3) is your field a text field? I don't know for a fact but it seems logical that if the field is of another type then font would be unavailable ...

    Re undoing it, yes, I did think of that, but there didn't seem any point - once the field is zero length I don't think the users will be able to see it in order to get in it, put some text back in and trigger the 'else' line (although admittedly I haven't actually tried ...)! I decided it's a decision they have to make on first running the template, and once it's gone, it's gone.

    By the way, I don't suppose you know of any snippets of code I could put in this template that would calculate APR, do you? I know this can be very complicated, but this template only gives a demonstration loan, which will always be over one year, interest only, paid once a month, capital repaid at end of loan. The only thing we have is a massive XL spreadsheet that requires several rows of input and the idea of converting it to pick up the loan amount, interest rate and above details and state the APR in this template is quite daunting!

    Cheers!
    Beryl M


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

    Re: Zero length text field? (WinNT/Word97)

    Hi Beryl,

    If you take a look at the document attached to <post#=365442>post 365442</post#>, you will see how you can do loan calculations using Word fields (under the heading 'Financial Calculations'). I don't really recommend it though and I'm sure you'll see why if you expand the field codes. In the same document, though, there are also the algoritms/formulae for doing this. The syntax is the same as in Excel and could fairly easily be converted to vba.

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  15. #15
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Zero length text field? (WinNT/Word97)

    Edited by JanB to correct typo in code

    Hi Phil,

    I've tested this both in Word 97 and Word 2003. There appeared to be 2 things wrong:
    1. you have to lift the protection temporarily in order to change the .Hidden property of the selection

    So, in this respect, the correct code would be:

    Sub Test
    ActiveDocument.Unprotect
    ActiveDocument.FormFields("MyFF").Select
    If Trim(ActiveDocument.FormFields("MyFF").Result) = "" Then
    Selection.Font.Hidden = True
    Else
    Selection.Font.Hidden = False
    End If
    ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
    End Sub

    2. the .Result of a hidden FormField turns out to be always an empty string!
    I tried to work-around this second problem using ActiveDocument.Bookmarks("MyRef").Range.Fields(1). Result.Text, but that turned out to always contain a space (ASCII 32), even if I put Trim() around it! So I'm afraid that the Else part of this code isn't going to work. (But that's all right for Beryl...)
    I don't have time to test this further at the moment.

Page 1 of 2 12 LastLast

Posting Permissions

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