You receive a VBA run-time error when you use MappedDataField name in Word 2003 (813982)



The information in this article applies to:

  • 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.

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: For additional information about the support options available from Microsoft, visit the following Microsoft Web site: 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.

Modification Type:MajorLast Reviewed:3/23/2006
Keywords:kbBug kberrmsg kbprb KB813982 kbAudEndUser