Microsoft KB Archive/298418

= The HeaderRecord string for Word's CreateDataSource method is limited in size to 255 characters =

Article ID: 298418

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft Office Word 2007
 * Microsoft Office Word 2003
 * Microsoft Word 2002 Standard Edition
 * Microsoft Word 2000 Standard Edition
 * Microsoft Word 97 Standard Edition

-



This article was previously published under Q298418



SYMPTOMS
When you create a new MailMerge data source for a Microsoft Office 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.



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

Additional query words: WD2003 WD2007

Keywords: kbautomation kbprb KB298418

-

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

© Microsoft Corporation. All rights reserved.