Microsoft KB Archive/99401

= ACC: How First Line of Data Is Used to Import Delimited Text =

Article ID: 99401

Article Last Modified on 1/18/2007

-

APPLIES TO


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

-



This article was previously published under Q99401



Novice: Requires knowledge of the user interface on single-user computers.



SUMMARY
The first line of data is extremely important when you are importing delimited text files. Microsoft Access 2.0 and earlier uses the first line of data to determine the following:


 * The number of fields
 * The data type for each field

For this reason, it is important to verify that the first line of data correctly reflects the rest of the data in the table. This article discusses some of the common problems you may encounter when the first line of data is incorrect and how to work around these problems.

In Microsoft Access 97, the Import Text Wizard (Text Import Wizard in version 7.0) offers greater flexibility. The wizard uses more than just the first line when determining the number of fields to create in a new table and it allows you to change the data type of the fields before they are actually imported. However, if lines far down in the text file contain more fields than the first few lines, the Import Text Wizard will not see them and the additional fields will be ignored. In this situation, use the technique described in the &quot;Other Workarounds&quot; section below.



MORE INFORMATION
To specify the structure that Microsoft Access should use, you can use the following steps instead of relying on the first line of data:


 * 1) Create a table in Microsoft Access that has the correct number of fields and the correct data type for each field.
 * 2) On the File menu, click Import.
 * 3) Select Text (Delimited) from the Data Source list and click OK.
 * 4) Select the text file and click OK.
 * 5) In the Import Text Options dialog box, click Append To Existing Table and specify the table you created in step 1.
 * 6) Click OK to import the file.

Determining the Number of Fields
Microsoft Access scans the first line of data to determine the number of fields in the text file. If successive records contain more fields, these are ignored and no error message is given. For example, suppose you have a text file that looks like the following:

  5959,&quot;John Doe&quot;,&quot;123 Main Street&quot; 5960, &quot;George Brown&quot;,&quot;55 Orange Avenue&quot;,&quot;MainTown&quot;,&quot;WA&quot;,&quot;USA&quot;

Because the first line only contains three fields, Microsoft Access creates the following table:

  Column 1     Column 2          Column 3 ---  5959         John Doe          123 Main Street 5960        George Brown      55 Orange Avenue

Note that the additional fields are ignored and no error message is generated.

Determining the Data Types
Microsoft Access scans the first line to determine the data type for each field. If the data type in the field is invalid, a &quot;Type Conversion Failure&quot; error message is generated in the Import Errors table. For example, if the following text file is imported

  5959,&quot;John Doe&quot;,&quot;123 Main Street&quot;,8/12/90 5960,&quot;George Brown&quot;,&quot;55 Orange Avenue&quot;,81290 ABCD,&quot;Jane Bell&quot;,&quot;78 West Street&quot;,8/12/90

Microsoft Access detects four fields with the following data types:

  Field      Data Type 1         Number 2         Text 3         Text 4         Date/Time

The second record fails to convert because the number 81290 in the fourth field is not a Date/Time data type, as determined by the first record value (8/12/90). The third record fails because &quot;ABCD&quot; in the first field is not a number. As a result, Microsoft Access reports type conversion errors in each case.

Other Workarounds
In addition to import appending the text file to an existing table, it is also possible to use a text editor to edit the first line of data to correctly reflect the number of fields and data types in the file.

If a field in the first row contains a number that is supposed to belong in a text field, type double quotation marks (&quot; &quot;) around the number in the first row. Microsoft Access will then correctly interpret the field as a text field.

Additional query words: import

Keywords: kb3rdparty kbhowto KB99401

-

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

© Microsoft Corporation. All rights reserved.