Import Data From A Text File
Import Data From A Text File
Importing data from a text file into a desktop database or an Access app is a two-step process-
you'll first prepare the text file for the import and then import the data into the database or app. A
text file contains unformatted readable characters, such as letters and numbers, and special
characters such as tabs, line feeds and carriage returns. Access supports the following file name
extensions — .txt, .csv, .asc, and .tab.
To use a text file as a source file for importing, the contents of the file must be
organized in such a way that the importing wizard can divide the contents into
records (rows) and fields (columns). Text files that are organized properly fall
into one of two types delimited files and fixed-width fields:
Delimited or Tip: If you are not sure whether your file has fixed-width or delimited fields,
fixed-width see types of text file formats.
Delimited file: Identify the delimiter. If the first row has column headings, the
order of columns need not match, but the name and data types of the text file
must exactly match the corresponding field data type.
Fixed-width fields file: Make sure each field is the same width in every record.
Text qualifiers Some delimited files might have field values enclosed within quotation marks
like this:
"Pernille Halberg",25,4/5/2006,"New York"
"Daniel Brunner",27,2000,"Chicago"
The quotation marks are called a text qualifier and are not required, unless one
the following conditions is true:
The field delimiter appears as part of the field values. For example, if comma
is used as the field delimiter, and New York, Chicago is a valid field value,
you must enclose the value within a pair of qualifiers, like this: "New York,
Chicago"
Check your text
file for these Do this
element
You want Access to treat non-text values, such as 0452934 and 0034539 as
text values and store them in a Text field.
When importing, you can specify whether the file uses a qualifier and, specify
the qualifier character. Make sure you use the same text qualifier throughout
the file and enclose only text values within the quotation marks.
To import only a portion of the text file, edit the source file before you import
because you cannot skip records (rows) during the import.
Skipping records You can skip fields (columns) only when you add data to a new table.
and values
When you add data to an existing table, the source data must have the same
number of columns as the destination table, and the data types of the source
data must match the data types of the destination table.
Delete all unnecessary blank lines in the text file. If you are adding the records
to an existing table and you have blank fields, make sure the corresponding
Blank lines and
field in the table accepts null values. A field will accept null values if its
fields
Required field property is set to No and its ValidationRule property setting
doesn't prevent null values.
Extraneous Review and remove extra characters, such as tabs, line feed, and carriage
characters returns.
Access scans the first 25 rows of a source file to determine the data type of the
fields in the table so, make sure that every column in the first 25 rows of the
source has the same data type. Also make sure any non-text values to be
Data types treated as text values are enclosed in quotation marks.
Note: Any mixed values in the rows following the 25th row of the source
might be skipped or converted incorrectly during the import. See how to fix
this in the Troubleshoot missing or incorrect values section.
Field names For delimited text files, if the file does not include the names of the fields,
place them in the first row. You can specify that the values in the first row
should be treated as field names when you import the data. When you import
fixed-width text files, you cannot use the first row as the field name.
Check your text
file for these Do this
element
Note: When you add a delimited text file to an existing table, make sure that
the name of each column exactly matches the name of the corresponding field
in the table or the import would fail. To find the names of the fields in the
existing table, open the table in Design view.
Close the source file to avoid data conversion errors during the import operation.
Check
Action
table
If the first row of the source text file does not have field (column) names,
First row make sure the position and data type of each column matches the
corresponding field in the destination table.
If any field is missing in the destination table, add them before importing. If
the destination table has fields that don't exist in the source file, you don’t
Missing or need to delete them from the table as long as the fields accept null values.
extra fields
Tip: A field will accept null values when its Required field property is set
to No and its ValidationRule property setting doesn't prevent null values.
If the table you are importing into has a primary key field, the source file
must have a column that contains values that are compatible with the primary
Primary key field. Also, the imported key values must be unique. If an imported
key record has a primary key value that already exists in the destination table, the
import would show an error message. If this happens, add unique key values
to the source data and try the import again.
Indexed If the Indexed property of a field in the table is set to Yes (No Duplicates),
fields the corresponding column in the source text file must contain unique values.
Click External Data >Text File and complete the steps in the wizard.
Issue Resolution
If the source file includes a field that contains only True or False values or
only Yes or No values, and you selected Yes/No as the data type for the
-1 or 0 values
field, you will see -1 and 0 in the table. Open the table in Design view, and
set the Format property to either True/False or Yes/No.
You cannot import multiple values in a field. The list of values are treated
Multivalued fields
as a single value and placed in a text field, separated by semicolons.
Data missing in Eliminate the duplicate values in the source file and try importing again.
primary key or Duplicate values cannot be stored in the primary key field of the destination
indexed fields table or in a field that has the Indexed property set to Yes (No Duplicates).
Null values When you open the table in Datasheet view, you might find that some
fields are blank. Do the following to minimize or eliminate any instances of
null values in the table:
If the first 25 source rows have values of different data types, open the
source file and rearrange the lines to make sure the first 25 rows do not
contain mixed values in any of the fields. Then, try importing again.
Enclose all non-text values that you want to store as text values in single or
double quotation marks.
During the import operation, select the appropriate data type for each field.
If the data type is incorrect, you might see null values or incorrect values in
Issue Resolution
Delimited files : In a delimited file, each record appears on a separate line and the fields are
separated by a single character, called the delimiter. The delimiter can be any character that does
not appear in the field values, such as a tab, semicolon, comma, space, and so on. The following
is an example of comma-delimited text.
1,Company A,Anna,Bedecs,Owner
2,Company C,Thomas,Axen,Purchasing Rep
3,Company D,Christina,Lee,Purchasing Mgr.
4,Company E,Martin,O’Donnell,Owner
5,Company F,Francisco,Pérez-Olaeta,Purchasing Mgr.
Fixed-width files: Each record appears on a separate line and the width of each field remains
consistent across records. For example, the first field of every record is always seven characters
long, the second field of every record is always 12 characters long, and so on. If the actual length
of a field's value varies from record to record, the values that fall short of the required width
must be padded with trailing space characters. The following is an example of fixed-width text.
1 Company A Anna Bedecs Owner
2 Company C Thomas Axen Purchasing Rep
3 Company D Christina Lee Purchasing Mgr.
4 Company E Martin O’Donnell Owner
5 Company F Francisco Pérez-Olaeta Purchasing Mgr.