Microsoft KB Archive/119698

From BetaArchive Wiki

WD: Form Fields Lose Text When Protected for Forms

Q119698



The information in this article applies to:


  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Microsoft Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a





SUMMARY

This article describes methods that allow you to:


  • Retain information you type into a form field when you protect a form.
  • Unprotect a forms document, perform a spell check, and retain information in the form fields when you reprotect the form.



MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please see the following page on the World Wide Web:

http://www.microsoft.com/partner/referral/

For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://support.microsoft.com/directory/overview.asp

Method 1: Alter the Protect/Unprotect Command Functionality

The following macros protect your form without causing you to lose the text that you entered into a form field. The macro can be stored in the actual form template, to allow you to manually unprotect and reprotect the form while preserving the form field contents.

If you name this macro "ToolsProtectDocument," then when you click on Protect Document on the Tools menu to protect your document for forms, the created macro will run instead of Word's built-in command of the same name.

   Sub MAIN
      Dim Dlg As ToolsProtectDocument
      Dlg.NoReset = 1
      n = Dialog(dlg)
      If n = - 1 Then ToolsProtectDocument Dlg
   End Sub 

Method 2: Create a Macro to Protect/Unprotect Your Document

The following example protects the active document for forms without resetting the contents of the form fields. Create the macro and assign the macro to a key, menu or toolbar button for easy access.

   ToolsProtectDocument .Type = 2, .NoReset = 1 

Method 3: Unprotect, Check Spelling or Update a Field, Reprotect a Document

In Word 7.x and later, the form field text is formatted for No Proofing. Use the following macro to temporarily Unprotect the form, change the language of the form fields, perform a spell check or update a field, and reprotect the form while preserving the text you've typed into the form fields. You can use this macro as an On Exit macro for the last form field so that you can check the spelling or update a field before you save the form.

Word 7.x:

   Sub MAIN
      ' Prevents cancellation of the macro.
      DisableInput
      ' Unprotects the form.
      ' Note: include .DocumentPassword argument for password
      ' protected form.
      ToolsUnprotectDocument
      ' Select body of document.
      EditSelectAll
      ' Set language.
      Language "English (US)"
      ' Go to start of document.
      StartOfDocument
      ' Perform the spell check
      ToolsSpelling
      ' Reprotect the document for forms without resetting fields.
      ' Note: include .DocumentPassword argument for password
      ' protected form.
      ToolsProtectDocument .NoReset = 1, .Type = 2
   End Sub 

Word 6.x:

   Sub MAIN
      ' Prevents cancellation of the macro.
      DisableInput
      ' Unprotects the form.
      ' Note: include .DocumentPassword argument for password
      ' protected form.
      ToolsUnprotectDocument
      ' Moves insertion point to top of document.
      StartOfDocument
      ' Starts Spell Checker.
      ToolsSpelling
      ' Reprotect the document for forms without resetting fields.
      ' Note: include .DocumentPassword argument for password
      ' protected form.
      ToolsProtectDocument .NoReset = 1, .Type = 2
   End Sub 

For additional information, please see the following articles in the Microsoft Knowledge Base:

Q110174 Preserving Text When Re-protecting a Form Without Macros


Q109757 WordBasic Examples: ToolsUnprotectDocument



REFERENCES

"Microsoft Word User's Guide," version 6.0, pages 305-26

"Microsoft Word Developer's Kit," version 6.0, pages 783-785

Additional query words: form field forms protect Unprotect lose lost text preserve retain keep update formfield formtext available spell

Keywords : kbmacro kbdtacode kbmacroexample winword macword word6 word7 word95
Issue type : kbhowto
Technology : kbHWMAC kbOSMAC kbWordSearch kbWordMacSearch kbWord700Search kbZNotKeyword2 kbWord600Mac kbWord601aMac kbWord601Mac kbWord600 kbWord600a kbWord600c kbWord700 kbWord700a


Last Reviewed: December 30, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.