Working with text database files directly is a pain, but they are very useful for transferring data between programs, such as when Access cannot read the original file's format.
Problem: MS Access cannot import a
database from MS Works.
Solution: MS Works saves the database as Text
MS Access imports the text file.
A text database uses a TAB or comma or other special character as the delimiter, which separates the fields, and usually uses a line break to separate records. The Import Text Wizard can normally guess what the delimiter is. If it is wrong, you can pick the correct character yourself.
A text database is a single table. You can import such data once you know how the fields and records are delimited (that is, separated).
You import from inside the database where you want the new data. You can append text data to an existing table, IF the fields are in the correct order and data type for the existing table.
The problems are the same as with spreadsheet data:
Import Errors: If some or all of the records fail to import properly, they will be saved in a new table called Paste Errors. You should look at the records to see which ones caused a problem. You may be able to tell what the problem was just by inspecting the records.
Common Causes of Paste Errors:
- Different table structure: Missing or extra fields
Example: Source might have a person's name in 1 field while the destination table use 3 fields- Mismatched data types:
Example: Source may have zip codes in a Number field while the destination table uses a text field.- Different field names:
Example: Source may use FirstName, without a space, while destination uses First Name, with a space.- Field order: If the first row of imported data does not contain the field names, then the fields must be in the same order as in the Access table.
- Duplicates in primary key: Imported data may have duplicate values in the field that is the destination table's primary key.
![]() |
Step-by-Step: Import Text File |
![]() |
What you will learn: | to import data from text file: new table with wizard to modify table design: field sizes, data types, Attachment field to import and append new text data to an existing table |
Start with: , resource files, worldtravel-FirstnameLastname.accb
You will add a table to
the
database worldtravel-Lastname-Firstname.accdb that you created in
the previous lesson .
Access has a wizard to help you import text data similar to the wizard for spreadsheet data. A plain text database file must be constructed in a way that makes it easy to tell where one field stops and another begins and where a record stops. Tabs and commas are most often used to create the separations between fields. Line breaks most often indicate the end of a record.
The data that you will import was constructed from a table that included some columns that you do not want. The fields are similar to those in the Staff table, but are not quite the same. The Import Text Wizard lets you omit those. So helpful!
In
step 1, choose Delimited.
Inspect the data. What character separates fields? In this text file the fields are separated by
a comma.
The wizard shows 'Sample data'. It will analyze only the first few records. This can sometimes cause problems if later records have a lot more characters in the field.
In
step 2 of the wizard, check the box for First Row Contains Field
Names.
Inspect all of the fields to be sure they are lined up correctly. You will need to scroll sideways in the dialog window.
Access did a good job of figuring out the structure of the data.
Leave the delimiter as comma and the Text Qualifier as the double
quote (").
Data not lined up correctly under field names: You may need to change the delimiter or back up and try "Fixed
Width" instead of "Delimited". Or maybe your data was not originally input correctly.
I
In step 4 select "Let Access add primary key".
Just as in the case with a spreadsheet, to get an AutoNumber field we
must let Access handle this transaction.
In step 5 accept the default table name "Clients".
Change the following field sizes and/or data types:
Save the table along the way. You will see a warning about possible data loss due to changing the field
sizes. There should not be a problem if you entered the values above
correctly.
Prefix and Suffix: 5
FirstName, MiddleName, Nickname: 20
LastName: 30
Title: 20
OrganizationName: 60
Address: 50
City: 30
State: 20
Region: 20
PostalCode: 15
Country: 30
HomePhone, WorkPhone, MobilePhone, FaxNumber, AlternativePhone: 20
EmailAddress: 75
Birthdate- Date/Time data type
Nationality: 50
DateUpdated - Date/Time data type
Hobbies - no change
HealthIssues: Memo or Long Text data type
Photograph: Delete. Save table. Create a new field named Photograph as Attachment data type. Move the field above the Notes field.
Notes: Memo or Long Text data
type
What do you do when your original text data source gets new records? How can you update the table in Access?
You can see from the illustration that a text database file is not easy to read!
It is important that the data you are importing matches the fields and field properties of the table to which you want to append it. There are many opportunities for errors here!
From the ribbon tab External Data in the Import & Link tab group, click on
.
The Get External Data - Text File dialog appears.
The File name box will show the path that you used last.
The default option chosen is "Import the source data into a new table in the current database."
Open the new table in Datasheet View and select the last 5 records, which are the new ones.
Keep clicking on OK in the error messages.
Finally a message says the you are about to "paste 2 record(s)."
At last!
Click on Yes.
Two new records appear.
Yet another message tells you that the records that failed to paste
are in a new table, Paste Errors.
Ah ha! The Paste Errors table has the 4 fields that were not imported originally into the Clients table: EmrgcyContactName, EmrgcyContactPhone, MembershipStatus, and DateJoined. Access pastes the data into the fields in order and helpfully(?) added new fields when it ran out of fields to paste into. That's a surprise! The last four field names had already been used, so in the Clients table Access created names for the new fields by adding a 1, like Hobbies1. Not so helpful in this situation. There was no message about these freshly created fields! <sigh>
The paste errors came, not exactly from extra fields, but from a mismatch of data types. Records that had a value in the Text field EmrgcyContact created an error when Access tried to paste it into the Date/Time field named DateUpdated in the Clients table. The paste failed. That was a good thing to happen, but it certainly is annoying that Access did not tell us exactly where the problem was.
Paste Errors:
Pasted into the Wrong Field
You can have an apparently successful paste and still have paste
problems.
Access will allow some pastes that you really don't want. For example, a State
value (which is text) will be accepted in a Postal Code field that is a
Text type field. Access cannot read the actual values. You must
carefully inspect the fields before you paste!
Select the 3 records in the table Paste Errors and Copy.
Gap in ID values: For some reason when a paste fails, Access acts like it had records and then deleted them. This creates a gap in the numbers. If you stopped the paste and tried it again, your numbers may have different gaps than what shows in the illustration.
Inspect the records in the Clients table.
Did all of the fields paste properly this time?
You may need to edit the data that you are importing first, to make sure that the fields match the fields in the existing Access table.