You are on page 1of 13

Importing Data into MS Access with ODBC (Page 1 of 6 ) Microsoft Access allows the user to import data originating

from a large number of different kinds of data sources. Access can establish a live link to the data, acting like a front end using data from the back end. This tutorial takes the reader step-by-step through the process of linking to ODBC databases so that the data can be manipulated in MS Access for the benefit of the end user. Converting any form of data to a format to fit the rows and columns of a table is at the core of RDBMS. Legacy data in flat files have the inherent limitations of data corruption, problems of maintenance, size, and so forth. When they get moved to the RDBMS, the individual pieces of data find themselves in well structured tables, and by establishing relationships of different kinds between these tables, finding data, and maintenance of data becomes a lot easier and a lot faster. One of MS Access's strength lies in its capability to import data originating from a large number of different kinds of data sources, text files, spread sheet files, and so on. In importing data, it has two different capabilities. It can import a table outright into the MS Access database, or it can establish a live link to the tables. In this second capacity, the data can stay where it is and the Access application acts as a front end using data from the backend. However, since it is file based, it functions more like a file server type of application. This makes Access well suited for multi-user scenarios, where several applications can feed off the single, main database. This tutorial takes the reader step-by-step through the process of linking to ODBC databases so that the data can be manipulated in MS Access for the benefit of the end user. As previously mentioned the data can also be imported, and this will be considered in a future tutorial. It is assumed that MS Access is installed (this tutorial used the following version: MS Access 2002 (10.2627)-SP1 on windows XP-professional platform) on the desktop, which has access to the other databases, files that needs to be linked.

Importing Data into MS Access with ODBC - Establishing a link to a database file (Page 2 of 6 ) Create a blank mdb file. The new database will have a default name, db1.mdb and it is recommended that you change this name to reflect your application. Here, it is called LinkToImport.mdb. The database is created in the default directory, C:\My Documents. At this point there are no user created objects, except for several utilities needed to create various objects, such as tables, queries, forms, reports, and so forth, as shown in this picture.

Establishing a Link Now click on File ->Get External Data-> Link Tables...as shown in this picture.

This opens up the My Documents folder for browsing, so that you can locate the file. It is quite possible that files may be located in other locations as well. Hence it is advisable that a preliminary search is made to determine the location of the various files. Clicking on the dropdown, Files of type: the various file types that Access can import into the database are displayed as shown.

The different file types supported are shown in the following list. In this tutorial we will be looking at the last item in the list, the ODBC databases.

Microsoft Access(*.mda; *.mdb; *.mde) dBase III, IV and 5 (*.dbf) Microsoft Excel (*.xls) Exchange() HTML documents(*.htm, *.html) Outlook() Paradox(*.db) Text files with several extensions(*.csv, *.txt, *.asc, *.tab) ODBC databases

Importing Data into MS Access with ODBC - Configuring an ODBC Source (Page 3 of 6 ) In order to connect to a database we need to have what is called an ODBC datasource. This is created using the 32bit ODBC Manager installed when Office 2000 is installed, or gets installed with the operating system. In Window XP Professional, you can get to the ODBC Administrator by going through Start ->Control Panel -> Administrative Tools -> ODBC Sources Short-Cut >ODBC Data Sources Administrator. Now click on ODBC Data Sources (the previous screen shot) to open the picture shown next. This is a part of the ODBC Data Sources Administrator macro. There are two tabs, File Data Source and Machine data Source. By default, it opens up the File Data Source tab in the clicked position. By choosing the Machine Data Source tab all the users of this machine and the system can use the data source. There are a number of data sources already created and these are shown in window.

User Data Source and ODBC Drivers Now click on New... to open the next window, where you choose whether only you can access, or all the users of the machine can access this resource. Here, the User Data Source choice is made. Click Next.

This opens up the next window, where you make a choice as to the driver you may want to use. As you can see here, there are a large number of drivers for diverse kinds of data sources, such MS Access, MS Excel, FoxPro, Oracle, and so on. This window is important as you can see the version and dates for the various drivers. We further assume that we will link to a file on an MSDE (Microsoft SQL Desktop Edition) database on the machine. After choosing SQL Server we click next.

You will be shown a short summary screen indicating the type of datasource you created: (User data Source) and the driver you have chosen (SQL Server). Click Finish to this screen. This opens up the next window where you need to configure certain features of the MSDE database.

Importing Data into MS Access with ODBC - Configuring the New Data Source to MSDE (Page 4 of 6 ) This brings us to the next window, Create a New Data Source to SQL Server, where you type a name for the ODBC data source you are creating. Here it is called LinkTut. You may give a description; here it is the title of this tutorial. Now click on the drop-down after the label, Which SQL server do you want to connect to?:. This should show all the available servers, here the XPHTEK/Test instance of the MSDE database is chosen. Click Next.

The window shown next pops up. In this window you need to choose the way you desire to get authenticated. There are two options, Windows integrated authentication, or SQL Server authentication. Whereas for the former you require a network logon, for the latter you require a login name and password recorded in the SQL Server to which you are connecting. Here the former is chosen. You may also place a check mark to use other default configuration settings. Click next.

In this screen, the default database master is brought up, but you can alter the default database. Here a database called myPubs has been chosen. You may accept the other defaults. Click Next.

There are a number of settings which set up various options, but defaults are good enough for this tutorial. Click Next and then click Finish to the window that shows up. You will come to the final window shown after the next picture. The picture shows all the configurational values you chose as well as those from the accepted defaults. If you find that the defaults are not the ones you want, you may edit the configuration settings by going through the same steps.

Finishing touches and testing the connectivity

You may test the connection and then click OK. The window that pops up shows LinkTut as a new DSN under the Machine Data Source tab as shown. Now click OK to this screen.

Importing Data into MS Access with ODBC - Importing the tables from MSDE (Page 5 of 6 ) The following screen shows up, where you make choices as to the tables you want to link to. Tables are the only objects you may link to. The prefix dbo for the tables indicate they are being linked with dbo permissions. Highlight the tables you want to link to, and click OK. You may also save the password with the link so that you may not need to enter this information again.

You are done! Now the link to the tables has been established as seen in this picture. Four tables have been successfully linked using the ODBC Connection to the MSDE database. Table names have come over with a dbo prefix and the icons show that they are ODBC database tables.

Importing Data into MS Access with ODBC - Imported table/Original table comparison (Page 6 of 6 )

Design view comparison These two pictures show the design of the tables that were linked and the original table design in the MSDE database. The data types in SQL Server are different from those of MS Access, and the linked table design features are not allowed to be altered.

Comparison of tables

Summary This step-by-step procedure should help in establishing ODBC links to tables in MSDE. The procedure is generic and can be used for other databases which one can find, or download drivers from third party vendors. As it was seen in this tutorial, the linked table data types will be those of the MS Access native type rather than of the originating database. The table design cannot be changed in the linked tables. Using MS Access with linked tables can effectively shield applications from data and make data accessible to a number of applications sharing the same data.

You might also like