Introduction.
Opening external data sources such as dBase files, Excel sheets, or tables from another MS Access database directly through VBA code is just one of the available options. For those who are not comfortable working with VBA, a better alternative allows you to access external data without permanently linking it to your Access database.
In either approach, one thing remains essential: you must know how to correctly reference different external data sources using the appropriate Source Database Path and Connection String values. Fortunately, these methods are quite straightforward to learn.
While understanding the syntax for ODBC (Open Database Connectivity) connection strings can be slightly challenging, there are some helpful shortcut techniques to determine them. However, we will set aside the ODBC discussion for now and revisit it later with a relevant example.
As demonstrated earlier, we can display values from Excel cells or ranges directly on MS Access form controls.
In the previous examples on opening Access tables, dBase tables, and Excel tables directly through VBA, you may have considered copying the SQL strings from the VBA code into queries and testing them there. If you haven’t done so yet, now is a good time to try—it’s a great way to understand how they work and to explore a few important details about their usage.
Open Recordset in Select Query, from External Access Database
Let us try to open an MS-Access Table from another Database directly in a Select Query.
Open one of your Databases or create a new one.
Select the Query Tab and Click the New Button on the Database Menu. Select the Design View from the displayed Options and click Close without selecting any Table from the list.
Click on the SQL Toolbar Button or select SQL View from the View Menu.
Copy and Paste the following SQL String in the SQL Editing Window, and Save the Query with the Name EmployeesQ.
SELECT Employees.* FROM Employees IN 'C:\Program Files\MicrosoftOffice\Office\samples\Northwind.mdb';
Note: If you are using MS-Access 2003, then change the Path to . . .\Office11\Samples\.
Open the Query in Datasheet View (View -> Datasheet View) to display the Employees Table contents from the Sample Database Northwind.mdb.
In the SQL String, an IN Clause is used for pointing to the correct database path, and the entire Path Name is put in quotes and ends with a semi-colon, indicating the end of the SQL String, which is applicable for all Queries.
A Different and Simple Method
There’s another way to accomplish this. The first part of the statement can be written directly in the SQL window, while the IN clause can be added separately in the Source Database and Source Connection String properties of the query. This approach eliminates the need to remember where to place the word IN, or where to insert opening and closing quotation marks, freeing you from such syntax concerns.
Create a New Query and open the SQL editing window following Steps 1 to 3 explained above.
Write the SQL string SELECT Employees.* FROM Employees;
Select Design View from the View Menu to change the Query from SQL View in Design View. We are now in the normal Query Design View. You will find the Employees Table object appearing in the Query Design without any Field Names showing in it.
Select Properties from the View Menu to display the Property Sheet of the Query.
Click on an empty area of the Query surface, to the right of the Table Name, to display the Query level Property Sheet correctly.
There are two properties on the Property Sheet that we are interested in.
- Source Database
- Source Connect Str
Here, we will be using only the Source Database Property for the external MS Access Table.
Enter the following Path Name in the Source Database Property, overwriting the text (current).
C:\Program Files\Microsoft Office\Office\samples\Northwind.mdb
Or with the change explained above for MS-Access 2003 cases.
Select Datasheet View from the View Menu.
You will now see the same result as the first Select Query we tried. If you change the Query into its SQL View and inspect the SQL String, you can see that the IN Clause is formed using the Source Database property Value.
Source Connect Str for dBase and Excel
You can use the same method for a dBase Table and an Excel Table (Named Range). In these cases, we need to use the Source Connect Str Property.
Example: opening the dBase Table directly.
Table Name: Customer.dbf
SQL String: SELECT Customer.* FROM Customer;
Source Database Property Value = C:\mydBase
Source Connect Str Property Value = DBASE IV; (check the semicolon at the end)
Replace the Customer table name and the Path C:\mydBase location address with your own dBase File Name and Folder name, where the dBase Table is located.
Example: opening an Excel Table (Named Range) directly.
Table Name: Categories
SQL String: SELECT Categories.* FROM Categories;
Source Database Property Value = C:\My Documents\Products.xls
Source Connect Str Property Value = Excel 5.0;
(note the semicolon at the end)
Replace the Categories table name and the Path C:\My Documents\Products.xls Excel file with your own.
NB: You must first define the Name Categories in the Excel Table Range using Insert -> Name -> Define before attempting to use the Name Categories in MS-Access Queries.
Next: MS-Access Live data in Excel









Great information! Ive been looking for something like this for a while now. Thanks!
ReplyDelete