PDA

View Full Version : Solved: Tabbing through hidden form fields



efto
03-31-2006, 12:24 AM
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


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

fumei
03-31-2006, 08:24 AM
I am sorry, but this is poor design. No, this is bad design. Could you explain of what possible advantage this is?

TonyJollans
03-31-2006, 08:30 AM
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 ...
':
':
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
':
':

efto
04-03-2006, 12:18 AM
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.

TonyJollans
04-03-2006, 04:16 AM
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.

lucas
04-03-2006, 07:23 AM
Thread marked solved