We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Use VBA to link tables in SQL Server

Medium Priority
650 Views
Last Modified: 2012-05-06
I have an MSAccess database that links tables to a SQL Server database via ODBC.  I would like to dynamically link those tables when the database is opened to avoid having the user needing the ODBC entry on their PC.  I can establish the link to the SQL Server database but from there, how do I LINK the tables.

This is how I establish the connection to the sql server database.  Can I use VBA code to link to the tables I need from here?
        strsql = "Driver={SQL server}; Server=" & g_dbserver & "; Port=1433; Option=0; Socket=; Stmt=; Database=" & g_db & "; Uid=" & g_dbuserid & "; Pwd=" & g_dbpassword & "; Network=DBMSSOCN;"
        OBJdbConnection.Open strsql
        objCommand.ActiveConnection = OBJdbConnection
        OBJdbConnection.CommandTimeout = 0
        objCommand.CommandTimeout = 0
Comment
Watch Question

Database Developer
CERTIFIED EXPERT
Commented:
In your example code you go on to use an ADO object which wouldn't play a part in your table linking.
What you do need though is the ODBC connection string you've built before that.

Then you have a wealth of sources for creating linked tables via code.
http://www.mvps.org/access/tables/tbl0009.htm
And JStreet's utility which Armen has made available to the world - mentioned on Tony's blog here (with a few others)
http://msmvps.com/blogs/access/archive/2008/10/02/j-street-s-access-relinker-available-for-download.aspx

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.