Microsoft KB Archive/181329

= ACC97: Incorrect Records in Query Exported to File =

Article ID: 181329

Article Last Modified on 1/22/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q181329



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



SYMPTOMS
If you modify an existing query and then export it to another file format without saving it, the expected data may not appear in the resulting file. For example, this behavior can occur when you export a query to a text file (*.txt), to Microsoft Excel 97 (*.xls), or to a dBASE file format (*.dbf).



CAUSE
When you export a query, Microsoft Access uses the SQL property of the QueryDef object to determine which records and fields should be exported. Modifications that you make to a query exist in a temporary object until you save the query. At that time, the SQL property of the QueryDef object is updated.



RESOLUTION
Save the query before you export it to another file format.



Steps to Reproduce Behavior
 Start Microsoft Access and open the sample database Northwind.mdb.  Create the following query based on the Shippers table:

      Query: qryExportTest Type: Select Query

Field: ShipperID Table: Shippers Field: CompanyName Table: Shippers Field: Phone Table: Shippers  Save the query as qryExportTest. On the Query menu, click Run. Note that the query returns three records.  On the View menu, click Design View and add the following criteria to the ShipperID field:

<pre class="fixed_text">      <> 3 </li> Run the query without saving it. Note that the query returns two records.</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 In dialog box, click Microsoft Excel 97(*.xls) in the Save As Type list.</li> In the File Name box, type qryExportTest.xls, and then click Export.</li> Start Microsoft Excel and open qryExportTest.xls. Note that in addition to the column names, the spreadsheet contains three records instead of the two records returned by the unsaved query.</li></ol>

<div class="references_section">