Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using Enter to Move Between Form Fields

    I borrowed some code from the Knowledge Base for enabling the Enter key to move between form fields in the protected Word 2000 form. <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q187/9/85.ASP>http://support.microsoft.com/support/kb/ar...s/Q187/9/85.ASP</A>

    The form is a custom mailing label. There are five address lines (form fields). The problem I'm having is when I use File/New and choose the template, it skips the first form field and places the cursor in the second field.

    I'm new to VB, any help will be appreciated!

    The code is shown below. The only thing I have changed is the macro name to "autonew".

    Sub autonew()
    ' Check whether the document is protected for forms
    ' and whether the protection is active.
    If ActiveDocument.ProtectionType = wdAllowOnlyFormFields And _
    Selection.Sections(1).ProtectedForForms = True Then
    ' Retrieve the bookmark of the current selection.
    ' This is equivalent to the name of the form field.
    myformfield = Selection.Bookmarks(1).Name
    ' Go to the next form field if the current form field
    ' is not the last one in the document.
    If ActiveDocument.FormFields(myformfield).Name <> _
    ActiveDocument.FormFields(ActiveDocument.FormField s.Count) _
    .Name Then
    ActiveDocument.FormFields(myformfield).Next.Select
    Else
    ' If the current form field is the last one,
    ' go to the first form field in the document.
    ActiveDocument.FormFields(1).Select
    End If
    Else
    ' If the document is not protected for forms,
    ' insert a tab stop character.
    Selection.TypeText Chr(13)
    End If
    End Sub
    egghead

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Using Enter to Move Between Form Fields

    Hi,
    As far as I can see, what you've done is take the code that moves from formfield to formfield and attached it to an autonew macro. What that means is that opening a new document based on this template automatically moves to the next formfield. You need the other 3 macros from the MSKB article - 1 to bind your code to the enter key when you create a new document, one to bind it when you open an existing document, and one to remove the binding when you close your template.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Using Enter to Move Between Form Fields

    For those looking, here is a link to the <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q187/9/85.ASP> knowledge base article</A>.

    Once my site is back up (soon I hope) you can follow the links on <A target="_blank" HREF=http://www.addbalance.com/word/wordwebresources.htm#Forms> my web resources page</A> for more information about forms. (addbalance.com/word/wordwebresources.htm#Forms)
    Charles Kyle Kenyon
    Madison, Wisconsin

  4. #4
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Using Enter to Move Between Form Fields

    Sorry, I must be so frustrated from my site being down that I completely missed that egghead had already posted the KB address.
    Charles Kyle Kenyon
    Madison, Wisconsin

  5. #5
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Enter to Move Between Form Fields

    Now that I read the directions more carefully, it does say that they need to be used together! <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

    How do I put each macro in then? (Sorry I'm so basic!)

    TIA
    egghead

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Using Enter to Move Between Form Fields

    Hi,
    As I recall from the KB article, if what you're trying to do is exactly what they say (i.e. enable the Enter key to move from field to field) then I think copying the code exactly and pasting it into your template module (just as you did with your autonew macro) should do what you need. If it doesn't, post back and let us know what's going wrong.
    HTH.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Enter to Move Between Form Fields

    Rory,

    When I pasted all four it did work, so thank you. I'm hoping you can help with a couple of glitches.

    On the original template I have default text "Begin typing then press tab". It was selected so the user could type right over it. With the macros the insertion point is in front of the default text instead.

    Second problem involves styles. Line one of the label has a style with extra paragraph spacing above ("Line 1"). The other four have "Line two" style without the extra spacing. With the macros all of the lines are Line 1 style.

    Finally, enter never returns to the top form field, it keeps adding more lines.

    That's it <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>. Thank for any help you can give!
    egghead

Posting Permissions

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