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

    Selecting Formfields (WinXP/Word2003)

    This is such a small thing but it's driving me nuts!! Does anyone know how to make VBA select a field in a protected document so that the field in selected in the way it would be if you had manually tabbed to it, ie the whole field selected ready to receive text, rather than as my code keeps doing, which is putting the cursor down *next* to the field?!

    I know it works the same - if you start typing the text goes in the field - but I have a set of less-than-computer-literate users here and if they can't *see* which field is selected (because it's highlighted) they get confused!

    Someone put me out of my misery, please!!
    Beryl M


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

    Re: Selecting Formfields (WinXP/Word2003)

    Try this, for a form field whose bookmark name is Text3:

    ActiveDocument.Bookmarks("Text3").Range.Fields(1). Result.Select

    See The best way to select a form field using VBA on the Word MVP site.

  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: Selecting Formfields (WinXP/Word2003)

    Thanks, Hans, but I just get error 5941: "The requested member of the collection does not exist." And yes, I had changed the bookmark name to that of the field I wanted, 'txtName', screenshot attached! My code therefore looks like this:

    ActiveDocument.Bookmarks("txtName").Range.Fields(1 ).Result.Select

    I also tried the 'goto' version mentioned in the article you pointed me to:

    Selection.GoTo What:=wdGoToBookmark, Name:="txtName"

    But that says, even more simply, "the bookmark does not exist" - although patently obviously it does!! It's not related to the document being protected, either - I tried it both with and without protection. - maybe someone can tell me what's going wrong?!
    Beryl M


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

    Re: Selecting Formfields (WinXP/Word2003)

    Can you attach the file?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  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: Selecting Formfields (WinXP/Word2003)

    No, sorry Andrew, confidentiality and all that! One of these days I'll take a job where every flippin' thing isn't far too confidential to be seen outside my office! Not yet, though, unfortunately ... <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>
    Beryl M


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

    Re: Selecting Formfields (WinXP/Word2003)

    I'm afraid we cannot help you then - at least I can't. Sorry.

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

    Re: Selecting Formfields (WinXP/Word2003)

    From the error messages and the view of your screenshot, it appears that that bookmark name is not in the file. Without the file to confirm this then there is not a lot we can do.

    Perhaps you could try ActiveDocument.Fields(1).Range or something similar instead of looking for a bookmark that apparently doesn't exist.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  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: Selecting Formfields (WinXP/Word2003)

    Andrew, you're not going to believe this (and I'm fairly certain you didn't expect it to work, either!) - but it did! Straight there, and selected exactly as if I'd tabbed into the field myself! The exact line I used is (it's the third field):

    ActiveDocument.fields(3).Result.Select

    Let's hear it for the throwaway comment just as everyone was giving up!! <img src=/S/joy.gif border=0 alt=joy width=23 height=23>
    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: Selecting Formfields (WinXP/Word2003)

    I experience the same every now and then. It often - but not always - happens when you doubleclick on a FormField (FF) to look at it's name or other properties and then leave the FF with Cancel instead of OK. In that case the cure is to open the FF again, change the name, click OK, open again, change to the original name an click OK again.
    Although the other solution, ActiveDocument.Fields(3).Select, does work it has the disadvantage that if you insert an FF before that one, you have to adapt the code.

  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: Selecting Formfields (WinXP/Word2003)

    Wow - hit the nail on the head! It worked first time!

    Another candidate for a starpost, I would say (both the tip about using okay to come out of the field and the line that puts the cursor in the right place without relying on the field being in the right position)!

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> again!
    Beryl M


Posting Permissions

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