Lab 02c
Lab 02c
You can easily import data from a variety of different sources, including text, Excel, XML, HTML,
ODBC datasources and more.
You can also link to external data sources, so that changes in the source file are reflected in your
Access database.
Establish a link to the external file, so that future updates are reflected automatically.
We will import the following CSV file into the Artists table.
ArtistId ArtistName
Note that this file includes an extra field that's not in our destination table. Not a problem. Access
will allow us to remove the extra field.
Also, the CSV file doesn't contain a header row, but that's fine. Access can deal with this too.
Launch the Import Wizard
Before starting, ensure that both the source file, and the destination table are closed.
To launch the wizard for a CSV file, click Text File from the External Data tab on the Ribbon.
You can also launch the wizard by right-clicking on a table and selecting an option from
the Import option.
Access needs the destination table to be closed before importing data. If you don't close it before
starting the import, Access will warn you later in the process, and offer to save and close the table
for you.
Select the Source File & Destination Table
Use the Browse... button to navigate to and select the import file (in our case, artists.csv).
Select Append a copy of the records to the table and then select the Artists table from the drop
down list of tables.
Click OK to continue.
You can just type the path directly into the File name field if you know the full path to the file (i.e.
instead of using the Browse... button).
Review the Format Options
This part of the Import Wizard will ask you to confirm the file's format. In our case, Access has
(correctly) detected that our file is in a delimited format.
Now Access will ask you to select the file's delimiter. In our case, Access has (correctly) detected that
our file uses a comma as its delimiter. If it was wrong, you can click another delimiter and see how
the data updates to reflect the new delimiter.
You can also select whether or not the file contains header rows. If the first row of your file contains
headers, click First Row Contains Field Names. Otherwise, leave it unchecked.
However, before continuing, click the Advanced... button, as we need to tell Access to skip the extra
field.
Skip the Extra Field
Access won't import the CSV file the way it is because it contains an extra field. The file contains 3
fields but our table only has two. Therefore we can only import two fields. We need to tell Access
which field to skip.
After skipping the extra field, you'll be back on the delimiter screen. Click Next >.
Run the Import
Once the import operation has completed, Access will ask you if you want to save the import steps
for another time. Check the box if you'd like to, otherwise leave it unchecked, and click Close.
Check that the data has been Imported
Now that the import has run, you should check the table to make sure that all data is in the correct
fields and it looks OK.