?
Solved

Use VBA to link tables in SQL Server

Posted on 2009-02-17
1
Medium Priority
?
625 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
0
Comment
Question by:CaroleTSullivan
1 Comment
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 2000 total points
ID: 23662551
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question