You can bring data from a text file into Access in two ways. If you want a copy of the data that you can edit within Access, import the file into a new or existing table by using the Import Text Wizard. If you simply want to view the latest source data within Access for richer querying and reporting, create a link to the text file in your database by using the Link Text Wizard.
This article explains how to import and link to a text file by using these wizards.
In this article
About text files and supported formats
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 or linking, the contents of the file must be organized in such a way that the importing and linking wizards can divide the contents into a set of records (rows) and each record into a collection of fields (columns). Text files that are organized properly fall into one of two types:
-
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. 6,Company G,Ming-Yang,Xie,Owner 7,Company H,Elizabeth,Andersen,Purchasing Rep 8,Company I,Sven,Mortensen,Purchasing Mgr. 9,Company J,Roland,Wacker,Purchasing Mgr. 10,Company K,Peter,Krschne,Purchasing Mgr. 11,Company L,John,Edwards,Purchasing Mgr. 12,Company M,Andre,Ludo,Purchasing Rep 13,Company N,Carlos,Grilo,Purchasing Rep
-
Fixed-width files     In a fixed-width file, 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. 6 Company G Ming-Yang Xie Owner 7 Company H Elizabeth Andersen Purchasing Rep 8 Company I Sven Mortensen Purchasing Mgr. 9 Company J Roland Wacker Purchasing Mgr. 10 Company K Peter Krschne Purchasing Mgr. 11 Company L John Edwards Purchasing Mgr. 12 Company M Andre Ludo Purchasing Rep 13 Company N Carlos Grilo Purchasing Rep
Import data from a text file
If your goal is to store some or all data that is in a text file in an Access database, you should import the contents of the file into a new table or append the data to an existing table. You can view and edit the imported data, and the changes you make to the data do not affect the source text file.
During the import operation, you can specify how the source file is organized, and whether you want to create a new table or append the data to an existing table.
Tip:Â If you aren't familiar with tables or how a database is structured, see the articles Create tables in a database or Database design basics.
At the end of the import operation, you can choose to save the details of the import operation as a specification. An import specification helps you repeat the operation at a later time without you having to step through the Import Text Wizard each time.
Common scenarios for importing a text file into Access
Typically, you import text data into Access for these reasons:
-
Some of your data is in a format not recognized by Access and you want to use that data in one of your databases. You can first export the source data as a text file and then import the contents of the text file into an Access table.
-
You use Access to manage your data, but you regularly receive data in text format from users of a different program. You import the data at regular intervals, and you want to streamline the import process to save time and effort.
Note:Â When you open a text file in Access (by changing the Files of Type list box to All Files in the Open dialog box and then selecting your text file), Access starts the Link Text Wizard, which allows you to create a link to the text file instead of importing its contents. Linking to a file is different from importing its contents. For more information about linking to text files, see the section Link to a text file, later in this article.
Prepare the source file
-
Open the source text file in a text editor, such as Notepad.
Note:Â You can import only one text file during an import operation. To import multiple files, repeat the import operation for each file.
-
Review the contents of the source text file and take action as described in this table.
Element
Description
Delimited or fixed-width
Make sure the file consistently follows one of the formats. If the file is delimited, identify the delimiter. If the file has fixed-width fields, make sure each field is the same width in every record.
Text qualifiers
Some delimited files might contain field values that are enclosed in single or double quotation marks, as shown here:
-
"Pernille Halberg",25,4/5/2017,"New York"
-
"Daniel Brunner",27,2018,"Chicago"
The character that encloses a field value is called a text qualifier. Text qualifiers are not required, but they are essential if either of the following 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"
-
You want Access to treat non-text values, such as 0452934 and 0034539 as text values and store them in a Text field.
During the import operation, you can specify whether the file uses a qualifier and, if so, specify the character that acts as the qualifier.
Make sure that the same text qualifier is used throughout the file and that only text values are enclosed within a pair of qualifiers.
Number of fields
The number of source fields must not exceed 255 — Access cannot support more than 255 fields in a table.
Skipping records and values
If you are interested in only a portion of the text file, edit the source file before you start the import operation. You cannot skip records during the import operation.
If you are adding the data to a new table, you can skip certain fields, but this option is not available if you are appending the contents to an existing table. When you append data to an existing table, the structure of the source data must match the structure of the destination table. In other words, 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.
Blank lines and fields
Delete all unnecessary blank lines in the file. If there are blank fields, try to add the missing data. If you are planning to append the records to an existing table, make sure the corresponding field in the table accepts null values. A field will accept null values if its Required field property is set to No and its ValidationRule property setting doesn't prevent null values.
Extraneous characters
Review and remove extra characters, such as tabs, line feed, and carriage returns.
Data types
To avoid errors during importing, make sure each source field contains the same type of data in every line. Access scans the first 25 rows of a file to determine the data type of the fields in the table. We highly recommend that you make sure that the first 25 source rows do not mix values of different data types in any of the fields. Also make sure that non-text values that are to be treated as text values are enclosed in single or double quotation marks.
If the source file contains mixed values in the rows following the 25th row, the import operation might still skip them or convert them incorrectly. For troubleshooting information, see the section Troubleshoot missing or incorrect values in an imported table, later in this article.
Field names
For delimited text files, if the file does not include the names of the fields, it is good practice to place them in the first row. During the import operation, you can specify that Access treat the values in the first row as field names. When you import fixed-width text files, Access does not give you the option of using the values in the first row as the field name.
Note:Â When you append a delimited text file to an existing table, ensure that the name of each column exactly matches the name of the corresponding field. If the name of a column is different from the name of the corresponding field in the table, the import operation fails. To find the names of the fields, open the destination table in Design view.
-
-
Close the source file, if it is open. Keeping the source file open might result in data conversion errors during the import operation.
Start the import process in Access
-
Open the Access database in which the imported data will be stored. If you don't want to store the data in any of your existing databases, create a blank database.
-
Before you start the import operation, decide whether you want to store the data in a new or existing table.
-
Create new table    If you choose to store the data in a new table, Access creates a table and adds the imported data to it. If a table with the specified name already exists, Access overwrites the contents of the table with the imported data.
-
Append to an existing table    If you are adding the data to an existing table, the import process appends the data to the specified table.
As you proceed, remember that most append operations fail because the source data does not match the structure and field settings of the destination table. To avoid this, open the table in Design view, and review the following:
-
First row    If the first row of the source text file does not contain field names, make sure the position and data type of each column matches those of the corresponding field in the table. For delimited text files, if the first row contains column headings, the order of columns and fields need not match, but the name and data type of each column must exactly match those of its corresponding field. When you import fixed-width text files, Access does not give you the option of using the values in the first row as the field name.
-
Missing or extra fields    If one or more fields are not in the destination table, add them before you start the import operation. However, if the destination table contains fields that don't exist in the source file, you need not delete them from the table as long as they accept null values.
Tip:Â A field will accept null values if its Required field property is set to No and its ValidationRule property setting doesn't prevent null values.
-
Primary key    If the table contains a primary key field, the source file must contain a column that contains values that are compatible with the primary key field. In addition, the imported key values must be unique. If an imported record contains a primary key value that already exists in the destination table, the import operation displays an error message. You must edit the source data so that it contains unique key values and then start the import operation again.
-
Indexed fields    If the Indexed property of a field in the table is set to Yes (No Duplicates), the corresponding column in the source text file must contain unique values.
-
-
-
The location of the import/link text wizard differs slightly depending upon your version of Access. Choose the steps that match your Access version:
-
If you're using the latest version of the Microsoft 365 subscription version of Access or Access 2019, on the External Data tab, in the Import & Link group, click New Data Source > From File > Text File.
-
If you're using Access 2016, on the External Data tab, in the Import & Link group, click Text File.
-
-
Access opens the Get External Data – Text File dialog box.
-
In the Get External Data - Text File dialog box, in the File name box, type the name of the source file.
-
Specify how you want to store the imported data.
-
To store the data in a new table, select Import the source data into a new table in the current database. You will be prompted to name this table later.
-
To append the data to an existing table, select Append a copy of the records to the table and then select a table from the drop-down list.
Note:Â To link to the data source by creating a linked table, see the section Link to a text file, later in this article.
-
-
Click OK.
Access scans the contents of the file and recommends how the file should be organized. If the file uses a delimiter to separate the fields, ensure that the Delimited option is selected. If the file has fixed-width fields, ensure that the Fixed Width option is selected. If you are unclear about whether your file has fixed-width or delimited fields, see the previous section, Prepare the source file.
Note:Â If the source text file contains tabs or other special characters, these are represented in the Import Text Wizard as small boxes between the columns of data.
-
Click Next.
The information that the wizard displays depends on whether you select the Delimited option or the Fixed-Width option.
Delimited
Select or specify the character that delimits the field values - Tab, Semicolon, Comma, Space, or Other. If the file users a text qualifier, in the Text Qualifier box, select either the double quotation mark (") or the single quotation mark ('). If the first row of the source file contains field names, select the First Row contains Field Names check box. Then, click Next.
Fixed-width
The wizard displays the contents of the file. If Access detects a columnar structure in the data, it places vertical lines in the data to separate the fields. Review the structure suggested by the wizard and, if necessary, follow the instructions on the wizard page to add, remove, or adjust the lines. Then, click Next.
-
If you chose to append the data, skip to step 13. If you are importing the data to a new table, click Next. At this point, you should review the field properties displayed in the wizard.
Note:Â The wizard page on which you can specify information about fields you are importing is not displayed if you are appending records to an existing table.
-
Click a column in the lower half of the wizard page to display the corresponding field's properties. Review and change, if you want, the name and data type of the destination field.
Access reviews the first 25 rows in each column to suggest the default data type for the corresponding field. If there are different types of values, such as text and numeric values, in the first 25 rows of a column, the wizard suggests a data type that is compatible with all or most of the values in the column — that is often the Text data type. Although you can choose a different data type, remember that values that are not compatible with the data type you choose are either ignored or converted incorrectly. For more information about how to correct missing or incorrect values, see the section Troubleshoot missing or incorrect values in an imported table, later in this article.
-
To create an index on the field, set Indexed to Yes. To altogether skip a source column, select the Do not import field (Skip) check box. Then click Next.
-
If the records are being added to a new table, the wizard prompts you to specify a primary key for the table. If you select Let Access add primary key, Access adds an AutoNumber field as the first field in the destination table, and automatically populates it with unique IDs, starting with 1. Click Next.
Note:Â The wizard page on which you can specify information about fields you are importing is not displayed if you are appending records to an existing table.
-
Access displays the final page of the wizard. If you are importing records into a new table, specify a name for the destination table. In the Import to Table box, type a name for the table. If the table already exists, a prompt asks you whether you want to overwrite the existing contents of the table. Click Yes to continue or No to specify a different name for the destination table.
What is the Advanced button used for?
The Advanced button in the Import Text Wizard allows you to create or open an import specification in the format used by earlier versions of Access. Unless you have import specifications from earlier versions of Access, we recommend that you do not use the Advanced button. Instead, if you want to save the details of this import operation, you can learn more about this procedure in the next section.
-
Click Finish to import the data.
Access attempts to import the data. If any of the data is imported, the wizard displays a dialog box that tells you the status of the import operation. Conversely, if the operation completely fails, Access displays the error message An error occurred trying to import file.
-
Open the destination table in Datasheet view. Compare the data in the table with the source file, and make sure the data appears to be correct.
What else should I know about importing?
-
For information on how to save the details of your import into a specification that you can reuse later, see the article Save the details of an import or export operation as a specification.
-
For information on how to run saved import specifications, see the article Run a saved import or export operation.
-
For information on how to schedule specifications to run at specific times, see the article Schedule an import or export operation.
-
For information on how to change a specification name, delete specifications, or update the names of source files in specifications, see the article Manage Data Tasks.
Troubleshoot missing or incorrect values in an imported table
If you see the message An error occurred trying to import file, the import operation completely failed. Conversely, if the import operation displays the page that prompts you to save the details of the operation, the operation managed to import all or some of the data. The status message also mentions the name of the error log table that contains the description of any errors that occurred during the import operation.
It is important to note that even if the status message indicates a successful operation, you should review the contents and structure of the table to ensure that everything looks correct before you start using the table.
Open the destination table in Datasheet view to see if all the data was successfully added to the table. You should then open the table in Design view to review the data type and other property settings of the fields.
The following table describes the steps you can take to correct missing or incorrect values.
Tip:Â While troubleshooting, if you find just a few missing values, you can add them directly to the table in Datasheet view. On the other hand, if you find entire columns or large number of values either missing or not imported properly, correct the problem in the source file. When you think you have corrected all known problems, repeat the import operation.
Issue |
Resolution |
---|---|
-1 or 0 values |
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 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. |
Multivalued fields |
Access does not support importing multiple values in a field. The list of values are treated as a single value and placed in a text field, separated by semicolons. |
Truncated data |
If data appears truncated in a column, try increasing the width of the column in Datasheet view. If increasing the width doesn't resolve the issue, the cause might be that the data type of a numeric field is set to Long Integer when it should have been set to Double. |
Data missing in primary key or indexed fields |
Records that you are importing contain duplicate values that cannot be stored in the primary key field of the destination table or in a field that has the Indexed property set to Yes (No Duplicates) in an Access database. Eliminate the duplicate values in the source file and try importing again. |
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:
|
In addition, you might want to review the error log table from the last page of the wizard in Datasheet view. The table has three fields — Error, Field, and Row. Each row contains information about a specific error, and the contents of the Error field should help you troubleshoot the problem.
Complete list of error strings and troubleshooting hints
Error |
Description |
---|---|
Field Truncation |
A value in the file is too large for the FieldSize property setting for this field. |
Type Conversion Failure |
A value in the text file or worksheet is the wrong data type for this field. The value might be missing or might appear incorrect in the destination field. See the entries in the preceding table for more information about how to troubleshoot this issue. |
Key Violation |
This record's primary key value is a duplicate — that is, it already exists in the table. |
Validation Rule Failure |
A value breaks the rule set by using the ValidationRule property for this field or for the table. |
Null in Required Field |
A null value isn't allowed in this field because the Required property for the field is set to Yes. |
Null value in AutoNumber field |
The data that you are importing contains a null value that you attempted to append to an AutoNumber field. |
Unparsable Record |
A text value contains the text delimiter character (usually double quotation marks). Whenever a value contains the delimiter character, the character must be repeated twice in the text file; for example: 10 - 3 1/2"" disks/box |
Link to a text file
You use linking to connect to data in another file without importing it — by doing so, you can view the latest data in both the original program and in the Access file without creating and maintaining a copy in Access. If you don't want to copy the contents of the text file into your Access database, but still want to run queries and generate reports based on that data, you should link to, rather than import, the text file.
When you link to a text file, Access creates a new table that is linked to the source file. Any changes you make to the source file are reflected in the linked table, however, you will not be able to edit the contents of the corresponding table in Access. If you want to make changes to the contents or structure of the data, you should open the source file and make the changes in it.
Common scenarios for linking to a text file from within Access
-
You use a program that outputs data in text format, but you want to use the data for further analysis and reporting by using multiple applications, one of them being Access.
-
The data you want to work is maintained by a different department or workgroup. You want to view the latest data, but don't want to edit or maintain a copy of your own.
If this is the first time you are linking to a text file
-
When you link to a text file, Access creates a new table, often referred to as a linked table. The linked table shows the data from the source file, but it doesn't actually store the data in the database.
-
You cannot link a text file to an existing table in the database. In other words, you cannot append data to an existing table by performing a linking operation.
-
A database can contain multiple linked tables.
-
Any changes that you make to the source file are automatically reflected in the linked table. However, the contents and structure of a linked table in Access are read-only.
-
When you open a text file in Access, Access creates a blank database and automatically starts the Link Text Wizard.
Steps for linking to a text file
-
Locate the text file, and open it in a word processing program, such as Word or Notepad.
Note that you can link to only one text file a time during a link operation. To link to multiple text files, repeat the link operation for each file.
-
Review the contents of the source file, and take action as described in the following table:
Element
Description
Delimited or fixed-width
Ensure that the file consistently follows one of the formats. If the file is delimited, identify the delimiting character. If the file has fixed-width fields, ensure that each field is the same width in every record.
Text qualifiers
Some delimited files might contain field values that are enclosed in single or double quotation marks, as shown here:
"Pernille Halberg",25,4/5/2017,"New York"
"Daniel Brunner",27,2018,"Chicago"
The character that encloses a field value is called a text qualifier. Text qualifiers are not required, but they are essential if:
-
The field delimiter appears as part of the field values. For example, if a 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, such as: "New York, Chicago".
-
You want Access to treat non-text values, such as 0452934 and 0034539, as text values and store them in a text field.
During the linking operation, you can specify whether the file uses a qualifier and, if so, you specify the character that acts as the qualifier.
Ensure that the same text qualifier is used throughout the file and that only text values are enclosed within a pair of qualifiers.
Number of fields
The number of source fields must not exceed 255 — Access cannot support more than 255 fields in a table.
Skipping records and fields
You can skip certain fields, but you cannot skip records.
Blank lines and fields
Delete all unnecessary blank lines in the file. If there are blank fields, try to add the missing data in the source file.
Extraneous characters
Review and remove extra characters, such as tabs, line feeds, and carriage returns.
Data types
To avoid errors during linking, ensure that each source field contains the same type of data in every line. Access scans the first 25 rows of a file to determine the data type of the fields in the table. We highly recommend that you ensure that the first 25 source rows do not mix values of different data types in any of the fields. You should also ensure that any non-text values that you want to be treated as text values are enclosed in single or double quotation marks.
If the source file contains mixed values in the rows following the 25th row, the import operation might display error values or convert them incorrectly. For troubleshooting information, see the section Troubleshoot #Num! and incorrect values in a linked table, later in this article.
Field names
For delimited text files, if the file does not include the names of the fields, it is a good practice to place them in the first row. During the linking operation, you can specify that Access treat the values in the first row as field names. However, when you import fixed-width text files, there is no option for treating the values in the first row as field names.
-
-
Close the source file, if it is open.
-
Open the database in which you want to create the link. Ensure that the database is not read-only and that you have the necessary permissions to make changes to the database.
If you don't want to store the link in any of your existing databases, create a blank database.
-
The location of the import/link text wizard differs slightly depending upon your version of Access. Choose the steps that match your Access version:
-
If you're using the latest version of the Microsoft 365 subscription version of Access or Access 2019, on the External Data tab, in the Import & Link group, click New Data Source > From File > Text File.
-
If you're using Access 2016, on the External Data tab, in the Import & Link group, click Text File.
-
-
Access opens the Get External Data – Text File dialog box.
-
In the Get External Data - Text File dialog box, specify the name of the text file that contains the data to which you want to link in the File name box.
-
Select Link to the data source by creating a linked table and then click OK.
The Link Text Wizard starts. This wizard guides you through the linking process.
-
Access scans the contents of the file and suggests how the file is organized. If the file uses a delimiting character to separate the fields, you should ensure that the Delimited option is selected. If the file has fixed-width fields, ensure that the Fixed Width option is selected.
-
Click Next.
-
The next page of the wizard that is displayed depends on whether you selected the delimited option or the fixed-width option.
Delimited files    Select or specify the character that delimits the field values. If the file users a text qualifier, in the Text Qualifier box, select either " or '. If the first row of the source file contains field names, select the First Row contains Field Names check box. Then, click Next.
Fixed-width files    The wizard shows the contents of the file. If Access detects a columnar structure in the data, it places vertical lines in the data to separate the fields. Review the structure suggested by the wizard and, if necessary, follow the instructions on the wizard page to add, remove, or adjust the lines. Then, click Next.
-
On the next page of the wizard, Access displays the field properties. Click a column in the lower half of the wizard page to display the corresponding field's properties. Review and change, if you want, the name and data type of the destination fields.
Access reviews the first 25 rows in each column to suggest the default data type for the corresponding field. If there are different types of values, such as text and numeric values, in the first 25 rows of a column, the wizard suggests a data type that is compatible with all or most of the values in the column. In most cases, that is the text data type. Although you can choose a different data type, remember that values that are not compatible with the chosen data type will either result in error values or get converted incorrectly. For more information, see the next section, Troubleshoot #Num! and incorrect values in a linked table.
What is the Advanced button used for?
The Advanced button in the Import Text Wizard allows you to create or open a link specification in the format used by earlier versions of Access. Access does not provide a way to save a link specification, unlike import and export operations, so if you want to save the details of a link specification, click the Advanced button, set the options you want, and then click Save As.
-
Click Next.
-
On the final page of the wizard, specify a name for the linked table and click Finish. If a table with that name already exists, Access asks if you want to overwrite the existing table. Click Yes if you want to overwrite, or No to specify a different table name.
Access attempts to create the linked table. If the table is successfully created, Access displays the message Finished linking table.... Open the linked table and review the fields and data to make sure you see the correct data in all the fields.
Troubleshoot #Num! and incorrect values in a linked table
Even if you see the message Finished linking table, you should still open the table in Datasheet view to verify that all the rows and columns show the correct data.
If you see errors or incorrect data anywhere in the table, take corrective action as described in the following table and try linking again. Remember that you will not be able to add the values directly to the linked table, because the table is read-only.
Issue |
Resolution |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
-1 or 0 values |
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 field, you will see -1 or 0 in the table. Open the table in Design view and set the Format property to True/False or Yes/No. |
||||||||||||
Multivalued fields |
When you link data, Access does not enable support for multiple values in a field. The list of values is treated as a single value and placed in a text field, separated by semicolons. |
||||||||||||
Truncated data |
If data appears truncated in a column, try increasing the width of the column in Datasheet view. If increasing the width doesn't resolve the issue, the cause might be that the data type of a numeric field is set to Long Integer, when it should have been set to Double. |
||||||||||||
#Num! |
When you open the table in Datasheet view, you might see that some fields contain #Num! instead of the actual value. Do the following to minimize or eliminate any instances of null values in the source file:
The following table lists cases where you will still see the #Num! error in fields:
|