PRB: The HeaderRecord String for Word's CreateDataSource Method is Limited in Size to 255 Characters (298418)



The information in this article applies to:

  • Microsoft Word 2002
  • Microsoft Word 2000
  • Microsoft Word 97 for Windows

This article was previously published under Q298418

SYMPTOMS

When you create a new MailMerge data source for a Word document, and you specify a HeaderRecord that is longer than 255 characters in length to Word's CreateDataSource method, you receive the following error message:
Run-time error '9105':
String is longer than 255 characters

CAUSE

This is an internal limitation to the MailMergeCreateDataSource function. The HeaderRecord cannot be longer than 255 characters.

RESOLUTION

If you need to create a new data source that has more fields than can be listed in a 255 character string, you cannot use CreateDataSource to create the new file. Instead, open a new document with Documents.Add and programmatically add a table to it with all the field names that you need. Save the file and use OpenDataSource to add the new document as the data source.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open Word and press ALT+F11 to open the Microsoft Visual Basic for Applications (VBA) Editor.
  2. In the current document, click Module on the Insert menu to add a new module.
  3. Paste the following code in the code window for the new module:
    Sub Test()
        Dim sTest As String
        sTest = "LastName,FirstName,MiddleInitial,Suffix,Title,NickName,"
        sTest = sTest & "JobTitle,Company,StreetAddress,City,State,Zip,"
        sTest = sTest & "PhoneNumber,FaxNumber,PagerNumber,CellPhone,"
        sTest = sTest & "Email1,Email2,Email3,HomeWebPage,AltWebPage,"
        sTest = sTest & "SocialSecurityNumber,DriversLicense,EmployeeID,"
        sTest = sTest & "HomeStreetAddress,HomeCity,HomeState,HomeZip"
           
        Application.ActiveDocument.MailMerge.CreateDataSource _
            "C:\TestData.doc", , , sTest
    End Sub
    					
  4. With the cursor inside the code block, press F5 to run the code.

Modification Type:MajorLast Reviewed:12/15/2003
Keywords:kbAutomation kbprb KB298418