Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms in Word: Protect or Destroy?

Status
Not open for further replies.

Redpop

Technical User
Sep 27, 2005
7
US
I've created several 'forms' in Word 2003 (xp) that use protection ('Protect Form' on the Forms toolbar) mostly to allow a checkbox to function, but also to keep formatting sane in these customer-facing documents.
The form fields are a bit difficult for my users to handle. They want to use spell check and bulleted lists, insert tables, etc. So, the users have figured out how to toggle off the protection, but when they toggle it back on, all their entered data is deleted.
Is this a version problem (most of my users have Word 2000)? Or do I have an owner / permission problem?
Should I just tell them to leave it off once they've turned it off, or is there a simple feature I've neglected to activate in the document?
 
It is not an owner/permission issue. Word defaults to NoReSet:=False when it turns on protection...in other words, it DOES reset the formfields.
The form fields are a bit difficult for my users to handle. They want to use spell check and bulleted lists, insert tables, etc
They are putting bulleted lists, and tables in formfields?????

Hmmmmm.

1. There may be design issues here. Perhaps the document could be redesigned to account for user requriements more.

2. Once that issue is resolved - and it certainly does sound like the document is not meeting user requirements in some way - you may want to consider removing the protection toggle from the menu. This would not stop a serious or determined person who knows Word/ Word VBA. But it may prevent most users from toggling the protection.

3. Rewrite the command for toggling the protection. I am not sure if you can do this for 2000, but for 2002 and higher you could rewrite the toggle to make NoReSet:=True. This would retain any data currently in the formfields.

Gerry
My paintings and sculpture
 
OK, good stuff so far..
I could live without the 'form' but it does a few things for me:
• It makes the checkbox work like a checkbox with one click (there's no linked code, it's just visual)
• It keeps formatting consistent
• It keeps users from changing other areas of the document
However, as you mention, it doesn't seem to be the right tool considering my other requirements.
If there's a better way, I'm all ears!
 
No, no...I am in total agreement with the use of protection, for precisely the reasons you give.

A formfield checkbox is perfect for "checking" something.

It keeps users from changing other areas of the document.

Uh, although regarding "formatting consistent"...ummm, Styles are what keeps format consistent. If you use them.

The reason I mentioned considering design is that you seem to have users that require structure in the document. Therefore, the document should have such structure.

What are the requirements? If they need bulleted lists...why don't they have them? If they need tables, why don't they have them? WHY are the users toggling protection? If it is be able to do their job (by being able to use bulleted lists and tables) then those requirements need to be accounted for within the use of protection that is locking parts that it is OK to lock.

Using protection to protect documents is NOT a bad idea - but it is a bad idea if the users are compelled to turn it off. So what is it, that is not there for them?

Gerry
My paintings and sculpture
 
Thank you for your attnetion.

The nature of the text they enter is variable. It's a description of a project. Sometimes it will have bullets, often times not. It depends on the user's writing style. They've learned the Alt-Fn-7 'bullet character' trick, but see that as a workaround.

There was only one occurence of a table, where the user wanted to detail the existing state (baseline numbers) before the improvement plan was revealed. The little Excel table had to be pasted BELOW the Text Form Field after the Form was unprotected.

Covering the entire page is a big 2-column table which shows a description (left column) and a place for text entry (right - with a Form field).

The checkbox is simple and could possibly be solved with straight text like this:
[X] YES
[ ] NO
But I prefer the checkbox control.

So.. Styles for formatting control? These will be overridden by the user if they copy & paste a text block though, right? I'm trying to maintain consistency. The forms are visible to the customer on the website as soon as the user completes it, so I don't get a shot at cleaning it up. The document has to take care of that itself.

Your thoughts?
 
It depends on what you mean by "completes it". If by that you mean the document is saved, then it is very possible to use the save command to "clean it up".

We all try to maintain consistency. Yes, if the user copies and pastes from another document, the default is to keep the original formatting. So...how are you keeping consistency now?

IF the document is totally structured with styles, then it is possible to run through the document on Save, checking for paragraphs that are NOT using appropriate styles, and correct them.

It is a great deal of work to retrofit existing documents to fully work with styles. It can be done though.
The nature of the text they enter is variable. It's a description of a project. Sometimes it will have bullets, often times not. It depends on the user's writing style. They've learned the Alt-Fn-7 'bullet character' trick, but see that as a workaround.
Could you elaborate? How are they entering this text?

Gerry
My paintings and sculpture
 
Microsoft addresses this problem in two of its KB articles:

(1)
The solutions in Article (1) work beautifully and RETAINS EVERYTHING when you manually protect/unprotect a document. It has you to create three macros:
• The first macro runs when you click the Protect Form button on the Forms toolbar.
• The second macro runs when you click either Protect Document or Unprotect Document on the Tools menu.
• The third macro allows you to specify which sections to protect while maintaining previous form field values.


(2)
WARNING! The workaround in Article (2) preserves only text fields. Check boxes and drop-down list selections are still lost when you unprotect and re-protect the field. Plus, a calculation field will no longer be updated and will maintain the current value until unlocked, even if it is printed or if a macro is run to update it.
 
This is a marco I use to use spellcheck. I link the macro to a field so when the user exits the field it auto runs.

Code:
Sub RunSpellcheck()

Dim oSection As Section, OriginalRange As Range, oDoc As Document

'If no documents open, quit macro
If Documents.Count = 0 Then
    Exit Sub
End If

Set oDoc = ActiveDocument

'Check what type of protection - if any - has been applied
Select Case oDoc.ProtectionType

    'If not protected, or if protected for tracked changes,
    'run spellchecker and quit
    '-------------
    Case wdNoProtection, wdAllowOnlyRevisions
        If Options.CheckGrammarWithSpelling Then
            oDoc.CheckGrammar
        Else
            oDoc.CheckSpelling
        End If
        Application.ScreenRefresh
        If oDoc.SpellingErrors.Count = 0 Then
            If Options.CheckGrammarWithSpelling Then
                MsgBox "The spelling and grammar check is complete", vbInformation
            Else
                MsgBox "The spelling check is complete", vbInformation
            End If
        End If
        System.Cursor = wdCursorNormal
        Exit Sub
    '-------------
    Case wdAllowOnlyComments
        'Don't want to run spellchecker if protected for comments
         Exit Sub
End Select

Set OriginalRange = Selection.Range
System.Cursor = wdCursorWait

'-------------
'-------------
'If we've got this far, it's protected for forms
'Now unprotect the document
oDoc.Unprotect Password:="[red]Form proctection password[/red]"
oDoc.SpellingChecked = False

'Check each section for its protection property -
'which you can get even afer unprotecting the document.
'If the section was protected, call a subroutine to spellcheck the formfields
'if it wasn't, spellcheck the section
StatusBar = "Spellchecking document ..."
For Each oSection In oDoc.Sections
    If oSection.ProtectedForForms Then
        Call CheckProtectedSection(oSection)
        If Cancelled Then
            'Boolean variable returned by CheckProtectedSection
            'procedure if user pressed Cancel buttoon
            Exit For
        End If
    Else
        If oSection.Range.SpellingErrors.Count > 0 Then
            Application.ScreenUpdating = True
            oSection.Range.CheckSpelling
            If oSection.Range.SpellingErrors.Count > 0 Then
                'User pressed Cancel button
                '(Pressing Ignore reduces the count, pressing Cancel doesn't)
                Exit For
            End If
        End If
    End If
Next oSection

'Re-protect the document
oDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="[red]Form proctection password[/red]"
OriginalRange.Select
Application.ScreenRefresh
If oDoc.Range.SpellingErrors.Count = 0 Then
    MsgBox "The spelling check is complete", vbInformation
End If

'Release variables from memory
System.Cursor = wdCursorNormal
Cancelled = False
CorrectedError = vbNullString
Set MyRange = Nothing

End Sub

Private Sub CheckProtectedSection(oSection As Section)

Dim FmFld As FormField

'check only the text formfields,
'don't check listboxes and checkboxes - this speeds up the code
Application.ScreenUpdating = False
For Each FmFld In oSection.Range.FormFields
    'Check to see if the field is a text formfield
    If FmFld.Type = wdFieldFormTextInput Then
        'Check if the field is a 'real' text field (no date, formula etc)
        If FmFld.TextInput.Type = wdRegularText Then
            'The following subroutine won't be called if Word 97 is in use
            If Not Left$(Application.Version, 1) = "8" Then
                Call TurnNoProofingOff(FmFld)
            End If
            FmFld.Range.SpellingChecked = False

            'Change the language constant in the following line if necessary;
            'when you type the = sign, a list of all supported language constants will
            'appear, and you can choose one from the list.
            FmFld.Range.LanguageID = wdEnglishUS  'Or whichever is appropriate for you

            'If the current form field contains errors, spellcheck the text in it
            If FmFld.Range.SpellingErrors.Count > 0 Then
                'The following condition is to allow for a Word 97 bug, which was fixed in 2000;
                'if the formfield is in a table an contains more than 1 paragraph, then
                'spellchecking it will crash Word 97
                If Left$(Application.Version, 1) = "8" _
                          And FmFld.Range.Paragraphs.Count > 1 _
                          And FmFld.Range.Tables.Count > 0 Then
                    Call Word97TableBugWorkaround(FmFld)
                    If Cancelled Then Exit Sub
                Else
                    'Set a range to the formfield's range in case the user
                    'accidentally destroys the formfield by overtyping its entire contents
                    Set MyRange = FmFld.Range
                    Application.ScreenUpdating = True
                    FmFld.Range.CheckSpelling

                    If IsObjectValid(FmFld) Then
                        If FmFld.Range.SpellingErrors.Count > 0 Then
                            'User pressed Cancel button
                            '(Pressing Ignore reduces the count, pressing Cancel doesn't)
                            Cancelled = True
                            Exit Sub
                        End If
                    Else
                        'If formfield was destroyed because the user overtyped its entire contents
                        CorrectedError = MyRange.Text
                        If Len(CorrectedError) = 0 Then
                            CorrectedError = MyRange.Words(1).Text
                        End If
                        Do While Not IsObjectValid(FmFld)
                            'If formfield was destroyed when the user corrected the spelling,
                            'reinstate it, and put the user's correction into its result
                            ActiveDocument.Undo
                        Loop
                        FmFld.Result = CorrectedError
                    End If
                End If
                Application.ScreenUpdating = False
            End If
        End If
    End If
Next FmFld

End Sub

Private Sub TurnNoProofingOff(FmFld As FormField)
    'This subroutine is called only in Word 2000 and above
    FmFld.Range.NoProofing = False
End Sub

Private Sub Word97TableBugWorkaround(FmFld As FormField)

'Unlink formfield (convert to text)
Set MyRange = FmFld.Range
FmFld.Range.Fields(1).Unlink
Application.ScreenUpdating = True
MyRange.CheckSpelling
If MyRange.SpellingErrors.Count > 0 Then
    'User pressed Cancel button
    '(Pressing Ignore reduces the count, pressing Cancel doesn't)
    Cancelled = True
End If
CorrectedError = MyRange.Text
'Undo to reinstate the formfield
Do While Not IsObjectValid(FmFld)
    ActiveDocument.Undo
Loop
FmFld.Range.Fields(1).Result.Text = CorrectedError
Application.ScreenUpdating = False

End Sub

When frustrated remember, in the computer world there is almost always a backdoor.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top