WD: GetFormResult$() Function Returns Incomplete Text String

ID: Q127743

The information in this article applies to:

SYMPTOMS

When you use the WordBasic function GetFormResult$() to return the text of a text form field (with a length set to Unlimited), the function returns only the first 255 characters of that text string.

CAUSE

In Word 7.x and earlier, the maximum size of the return string of GetFormResult$() and SetFormResult is 255 characters.

In Microsoft Word 97 for Windows and Word 98 Macintosh Edition, the maximum size is 65,279 characters.

RESOLUTION

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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/supportnet/refguide/ 

GetBookmark$():

To retrieve the full text string, use the GetBookmark$() function. GetBookmark$() returns the full text string and a form field header containing the field of origin. To return the text string alone, the macro must strip off the header.

The following sample macro returns the entire contents of a text form field using the GetBookmark$() function:

   Sub MAIN
      ' Sets contents of form field Text1 to a$.
      a$ = GetBookmark$("Text1")      
      ' Strips off the form field header.
      a$ = Mid$ (a$, 10)
      ' Unprotects the active document.
      ToolsUnprotectDocument
      ' Moves the insertion point down 1 line.
      LineDown
      ' Inserts form field contents into the document.
      Insert a$
      ' Reprotects document without resetting form
      ' field values back to defaults.
      ToolsProtectDocument .NoReset=1
   End Sub

SetFormResult:

To work around the problem with SetFromResult, use the following sample macro:

   Sub MAIN
      a$ = InputBox$("Type more than 255 characters")
      ' Goto the form field's bookmark name.
      EditGoTo "Text1"
      ' Unprotect the active document.
      ToolsUnprotectDocument
      Insert a$
      ' Reprotects document without resetting form
      ' field values back to defaults.
      ToolsProtectDocument .NoReset = 1
   End Sub

Additional query words: formfields limits getformresult
Keywords          : kbdtacode wordnt kbmacroexample winword ntword macword word6 word7 word95 
Version           : WINDOWS:6.0,6.0a,6.0c,7.0,7.0a; MACINTOSH:6.0,6.0.1,6.0.1a
Platform          : MACINTOSH Win95 WINDOWS winnt
Issue type        : kbprb

Last Reviewed: April 9, 1999