Consulting

Results 1 to 6 of 6

Thread: Solved: Tabbing through hidden form fields

  1. #1
    VBAX Regular efto's Avatar
    Joined
    Aug 2005
    Posts
    23
    Location

    Solved: Tabbing through hidden form fields

    Hi there!

    I have a template that contains tables in which are hidden rows with form fields. There is a macro which hides the rows if there is no input in the form fields. If the user changes his mind and wants to give input, there is a macro which unhides the rows.
    But now there is a problem because tabbing through form fields selects also the hidden form fields. In order to fix this I have the following macro that is assigned to every form field on entry. But instead of jumping from one unhidden form to next unhidden form, it stops somewhere in between selecting a form field even if it is hidden. If I debug this code going step by step, everything works fine. Any solution, please?

    Efto

    [vba]
    Sub TabUnhidden()

    If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect Password:=""
    End If
    If ActiveWindow.View.ShowAll = False Then
    If ActiveWindow.View.ShowHiddenText = False Then
    If Selection.Font.Hidden = True Then
    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.FormFields.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
    End If
    End If
    End If
    If ActiveDocument.ProtectionType = wdNoProtection Then
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
    NoReset:=True
    End If
    End Sub
    [/vba]

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I am sorry, but this is poor design. No, this is bad design. Could you explain of what possible advantage this is?

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi efto,

    Selecting a FormField does not count as Entering it and the macro does not fire. The easiest way with this code is just to change the Condition to a Loop ...
    [vba] ':
    ':
    If ActiveWindow.View.ShowHiddenText = False Then
    Do While Selection.Font.Hidden = True
    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.FormFields.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
    Loop
    End If
    ':
    ':[/vba]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  4. #4
    VBAX Regular efto's Avatar
    Joined
    Aug 2005
    Posts
    23
    Location
    Thank you very much Tony!
    Now it works the way I wanted to.

    PS: I can not use the Thread Tools to make this thread solved.

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I believe there has been a problem with marking threads solved since the board was upgraded. I think admins can do it and probably will when one of them sees that it wants doing.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Thread marked solved
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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