Microsoft KB Archive/178743

= ACC: Exported Query Expression Truncated at 255 Characters =

Article ID: 178743

Article Last Modified on 1/22/2007

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q178743



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you export a query that contains an expression that results in more than 255 characters, the expression is truncated in the exported file.



CAUSE
Microsoft Access evaluates the expression as a Text field, and Text fields have a maximum length of 255 characters. When you export the query, Microsoft Access truncates anything after the 255th character.



RESOLUTION
Use an append query to append the data to a table containing a Memo field, and then export the table. The following example creates a table to store the results of a query expression that exceeds 255 characters:

 Start Microsoft Access and open the sample database Northwind.mdb.  Create the following table in Design view:

       Table: EmpNotes Field Name: EmpName Data Type: Text Field Name: Comments Data Type: Memo  Save the EmpNotes table and close it. You do not need to create a primary key.  Create the following query in Design view based on the Employees table. The second expression, called Comments, will result in field lengths greater than 255 characters:

       Query: MemoExpr Type: Select Query

Field: Full Name: [FirstName] & " " & [LastName] Table: Employees Field: Comments: [HireDate] & ": " & [Notes] Table: Employees  On the Query menu, click Append Query.</li> In the Append dialog box, type EmpNotes in the Table Name box, and then click OK.</li> Select EmpName in the Append To row of the Full Name field in the QBE grid; the Append To row for the Comments field fills in automatically because the field name in the query and the field name in the table are the same.</li> On the Query menu, click Run. Click Yes when prompted that you are about to append the rows.</li> Close the MemoExpr query. You do not need to save it.</li> Export the EmpNotes table to whatever format you want. The full length of the Comments field will be preserved.</li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Start Microsoft Access and open the sample database Northwind.mdb.</li>  Create the following query in Design view based on the Employees table:

<pre class="fixed_text">     Query: qryTruncate ---     Type: Select Query

Field: Full Name: [FirstName] & " " & [LastName] Table: Employees Field: Comment Length: Len([Comments]) Table: Employees Field: Comments: [HireDate] & ": " & [Notes] Table: Employees </li> Save the qryTruncate query and close it.</li> Select the qryTruncate query in the Database window.</li> On the File menu, click Save As/Export.</li> In the Save As dialog box, click "To an External File or Database," and then click OK.</li> In the Save Query 'qryTruncate' In dialog box, select Text Files in the Save As Type box. Note the folder where the file will be stored in the Save In box, and then click Export.</li> When the Export Text Wizard appears, click Finish.</li> Using Notepad or another text editor, open the qryTruncate.txt file. Note that for any record where the Comment Length field is greater than 255, the Comments field is truncated at the end. This is true for the Andrew Fuller, Steven Buchanan, Michael Suyama, and Robert King records.</li></ol>

<div class="references_section">