Above Header LeaderBoard <body> <!--Google Navigation Bar--> <script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener("load", function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <iframe src="http://www.blogger.com/navbar.g?targetBlogID=34083602&amp;blogName=LEARN+MS-ACCESS+TIPS+AND+TRICKS&amp;publishMode=PUBLISH_MODE_FTP&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;searchRoot=http%3A%2F%2Fblogsearch.google.com%2F&amp;blogLocale=en_US&amp;homepageUrl=http%3A%2F%2Fwww.msaccesstips.com%2F" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe" allowtransparency="true" title="Blogger Navigation and Search"></iframe> <div></div>
Header Right Columns
www.msaccesstips.com

LEARN MS-ACCESS TIPS AND TRICKS

Home

LEARN MS-ACCESS TIPS AND TRICKS

↑ Grab this Headline Animator

Your Ad Here
Friday, August 15, 2008

Database Connection String Properties

Opening external data sources like dBase, Excel, Table from another MS-Access Database directly in VBA Code is only one of the options available to us. Those who are not comfortable with VBA have a better and much easier method available, without linking them permanently to MS-Access Database. In either case one thing is certain that we must know how to reference different external data sources correctly with Source Database Path and Connection String Values. But, these are very easy to learn.


We may face little difficulty in finding ODBC (Open Database Connectivity) Connection string Syntax, but this also we can find out by going through some shortcut tricks. Let us not mix the ODBC part now with our current example and we will deal with it later.


We have seen that we can display Values from Excel Cells or Range directly on MS-Access Form controls.


After going through the earlier examples for opening Access Table, dBase Table and Excel tables directly in VBA, I hope at least few readers thought of copying the SQL string presented in the VBA Code into a Query and try them out. If not, it is time to do that. It is a better option to understand them and to look into few things associated with their usage.


To start with, let us try opening an MS-Access Table from another Database directly in a Select Query.



  1. Open one of your Databases or create a new one.

  2. Select the Query Tab and Click the New Button on the Database Menu. Select Design View from the displayed Options and Click Close without selecting any Table from the list.

  3. Click on the SQL Toolbar Button or select SQL View from View Menu.

  4. Copy and Paste the following SQL String in the SQL Editing Window, Save the Query with the Name EmployeesQ.



  5. SELECT Employees.*
    FROM Employees IN 'C:\Program Files\MicrosoftOffice\Office\samples\Northwind.mdb';



    Note: If you are using MS-Access2003 then change the Path to …\Office11\Samples\...


  6. 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 SQL String, which is applicable for all Queries.


There is another way that you can do this. But, the first part you have to write in SQL window and the IN Clause part we can add separately in the Source Database and Source Connection Str properties of the Query so that you don't have to remember where to put the word IN or where to put the Opening/Closing quotes or worry about such syntax issues.


  1. Create a New Query and open the SQL editing window following Steps-1 to 3 explained above.

  2. Write the SQL string SELECT Employees.* FROM Employees;

  3. Select Design View from View Menu, to change the Query from SQL View to Design View. We are now in the normal Query Design View. You will find the Employees Table object is appearing on the Query Design without any Field Names showing in it.

  4. Select Properties from View Menu to display the Property Sheet of the Query.

  5. Click on an empty area of the Query surface, to the right of the Table Name, to display the Query level Property Sheet correctly.

  6. 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 external MS-Access Table.


  7. Enter the following Path Name in the Source Database Property over-writing the text (current).


  8. C:\Program Files\Microsoft Office\Office\samples\Northwind.mdb


    or with the change explained above for MS-Access2003 cases.

  9. Select Datasheet View from View Menu.



You will now see the same result as of 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.


You can use the same method for dBase Table and Excel Table (Named Range). In these cases we have to use the Source Connect Str Property also.


Example: opening 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 Excel Table (Named Range) direct.


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;

(check 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 Excel Table Range using Insert - - > Name - - > Define before attempting to use the name Categories in MS-Access Queries.


StumbleUpon Toolbar



Linking with AS400 Tables
Repairing Compacting Database with VBA
Database Open Close Event Alerts
ListBox Items and Date:Part-2
ListBox Items and Date:Part-1

Labels:

0 Comments:

Post a Comment

Note:Comments subject to Review by Blog Author before displaying.

Links to this post:

Create a Link

<< Home

Page Footer

Creative Commons License
Learn MS-Access Tips and Tricks by msaccesstips.com is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 India License.



This Page is best viewed with 1280 x 1024 Resolution

Sidebar Left
   FEATURED LINKS
SITEMAP
Command Button Animation
3D Headings on Forms
MsgBox & Office Assistant
Reminder Ticker
MS-Access & E-Mails
Automated E-Mail Alerts
MsgBox with Options Menu
Colorful Command Buttons
Configure Lotus Notes
Alerts through Network
Running this site has become a costly affair as the revenue from Ads is not sufficient to support it. If you find these pages informative & useful and would like to extend a helping hand, then please do it here.





Link Back to us with this Button

Learn MS-Access

Copy and Paste this HTML Code in your Webpage


Add to Technorati Favorites

Programming Blogs - Blog Catalog Blog Directory
Powered by FeedBurner
Add to Google

Software
Computers blogs
TopOfBlogs



AddMe - Search Engine Optimization Submit Your Site Free!
Go BlogZ Ave Blogs
eBlogzilla Changing LINKS
LS Blogs Blogarama
blog search directory BlogUniverse
Find Blogs in Directory RSS Directory
blogskinny.com ShowcaseBlogs.com
Amfibi

Search Engine Optimization and SEO Tools
Dmegs Web Directory Takeaway for Sale Businesses For Sale
Free Submission Directory Free site submission

Free Listing
 

Sidebar Right Top



Free Page Rank Checker

AddThis Social Bookmark Button

Enter your email address:

Delivered by FeedBurner



Top Blogs

Microsoft Access is the Jewell among MS-Office suite of Applications. Its Security features are excellent and works fine in Network environment. MS-Access can link/upload data from any Data Source. Applications that you design should be user-friendly and visually pleasing too. Here I would like to share my experience in Microsoft Access Programming with you and I am sure that you will find them interesting too.

My Photo
Name: Ramachandran Pillai
Location: Ruwi, Oman


If you need a Demo of any of the Topic explained here, send me an E-mail to: aprpillai@msaccesstips.com
with the Topic Description, I shall try to send a sample database to you.


Sidebar Right Top

Access Tips | Email | Reports | Report Tricks | Graphs | Forms | Menus | Animation | Security | Internet | How TOs | Linking | Query | Progress Meter | Alerts | Process Tips | Access Functions |





Site Designed by:www.msaccesstips.com