Microsoft KB Archive/211366

= WD2000: Run-time Error with Missing FormField Bookmark Names =

Article ID: 211366

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Word 2000 Standard Edition

-



This article was previously published under Q211366





SYMPTOMS
When you attempt to access a form field using Microsoft Visual Basic for Applications commands, and the bookmark name for the form field is missing, you may receive one of the following error messages:

Run-time error: "-2147467259" Method Name of Object FormField Failed

-or-

Run-time error: "5941" The requested member of the collection does not exist.



CAUSE
When you copy and paste a form field to a different location, a new form field is created. This new form field does not have a bookmark name. By design, Word cannot return the object if the name is invalid.



RESOLUTION
Use one of the following methods to correct this problem.

Method 1: Type a Valid Bookmark Name
Make sure each form field in the active document contains a valid bookmark name. To enter a bookmark name for a form field, double-click the form field to display the form field Options dialog box, and then, in the Bookmark Name box, type a valid bookmark name.

The following characters are invalid in a bookmark name:  Any character whose ASCII value is less than 29 and greater than 127.

-or-  Characters listed in the following table.   Character ASCII code      Character ASCII code     Character ASCII code ---

-        Chr(30)            Chr(32)         ! Chr(33) "        Chr(34)         #         Chr(35)         $         Chr(36)   %         Chr(37)         &         Chr(38)         '         Chr(39)   (         Chr(40)         )         Chr(41)         *         Chr(42)   +         Chr(43)        ,         Chr(44)         -         Chr(45)   .         Chr(46)         /         Chr(47)         :         Chr(58)   ;         Chr(59)         <         Chr(60)         =         Chr(61)   >         Chr(62)         ?         Chr(63)         @         Chr(64)   [         Chr(91)         \         Chr(92)         ]         Chr(93)   ^         Chr(94)         `         Chr(96)         {         Chr(123)   |         Chr(124)        }         Chr(125)        ~         Chr(126)                    

Method 2: Use a Macro to Assign a Bookmark Name
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 visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

Use the following macro example to assign a bookmark name to each form field that does not have a bookmark name: Sub AddFormFieldName

Dim x As Integer Dim myField As FormField Dim newDoc As Document

x = 1

For Each myField In ActiveDocument.FormFields myField.Select If myField.Name = "" Then Application.WordBasic.FormFieldOptions Name:="Test" & x        x = x + 1 End If

Next myField

End Sub NOTE: Each form field that does not contain a bookmark name is assigned a bookmark name sequentially; for example, Test1, Test2, Test3, and so on.

