Microsoft KB Archive/813982

= You receive a VBA run-time error when you use MappedDataField name in Word =

Article ID: 813982

Article Last Modified on 1/25/2007

-

APPLIES TO


 * Microsoft Office Word 2007
 * Microsoft Office Word 2003

-





For a Microsoft Word 2002 version of this article, see 282567.



SYMPTOMS
When you run a Microsoft Visual Basic for Applications macro to return a merge field from your Microsoft Outlook Contacts folder and you use the MappedDataField name, you may receive the following error message:

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

To determine the unique number that is associated with the message that you receive, press CTRL+SHIFT+I. The following number appears in the lower-right corner of this message:

201064



CAUSE
This problem may occur if the MappedDataField name the macro is returning contains more than one word. For example, this problem occurs if the MappedDataField name that is returned is the Business Fax, Zip/Postal Code, Home Fax, E-mail Address or Web Page fields.

Microsoft Word replaces spaces in a mail merge field with an underscore character ( _ ). However, when you use Outlook contacts as the data source, the returned names from the MappedDataFields do not contain the underscores.



WORKAROUND
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, see the following Microsoft Web site:

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

For additional information about the support options available from Microsoft, visit the following Microsoft Web site:

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

When you want to return the merge field for a MappedDataField object, use the DataFieldIndex property instead of the DataFieldName property.

Note The following sample macro uses the DataFieldIndex of a MappedDataField constant (wdBusinessFax) to determine the fax number for the first record in the data source. Sub MappedField Dim objDsource As MailMergeDataSource Dim BFAXindex As Integer Dim objBFX As MailMergeDataField 'Return the mail merge data source. Set objDsource = ActiveDocument.MailMerge.DataSource With objDsource 'Set the first record as the active record. .ActiveRecord = wdFirstDataSourceRecord 'Return the index for the wdBusinessFax MappedDataField. BFAXindex = .MappedDataFields(wdBusinessFax).DataFieldIndex 'Return the corresponding mail merge field. Set objBFX = .DataFields(BFAXindex) 'Return the business fax number. MsgBox objBFX.Value End With End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Additional query words: wd2003 prb vbe vba OfficeErrorMessages 10096 WD2007

Keywords: kbofficealertid kbbug kberrmsg kbprb KB813982

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.