Solved

Automatic Table linking (MSAccess as frontend, MSSQLsrvr as backend)

Posted on 2001-06-13
3
519 Views
Last Modified: 2008-10-14
I'm using Access 97 as front end and MSSQLServer as backend. What is the best way to automatically relink tables through code.

If anybody can give some sample code, i would really be thankful....
0
Comment
Question by:kullo
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
dovholuk earned 200 total points
ID: 6185743
here's a similar version of the code i use. here are the steps to use this code:

1  copy and paste the following code into a NEW module.

'******************************* BEGIN COPY ********************************
Global Const UID        As String = "username"
Global Const PWD        As String = "password"
Global Const DSN        As String = "DSN_Name"
Global Const DATABASE   As String = "DB_Name"
Global Const ADDRESS    As String = "10.10.10.10,1433"

Function ReattachTables()

   Dim ws   As DAO.Workspace
   Dim con  As DAO.Connection
   Dim rs   As DAO.Recordset
   Dim t    As DAO.TableDef

Set ws = DBEngine.CreateWorkspace("", "", "", dbUseODBC)
Set con = ws.OpenConnection("TempCon", , True, _
   "ODBC;DSN=" & DSN & ";UID=" & UID & ";PWD=" & PWD & ";DATABASE=" _
   & DATABASE & ";ADDRESS=" & ADDRESS)

Set rs = con.OpenRecordset("SELECT * from SysObjects where xtype = 'U '")

Do Until rs.EOF
   AttachTable rs!Name, "__dbo_" & rs!Name
   rs.MoveNext
Loop

End Function

Function AttachTable(tblServerName As String, tblCurrentDBName As String)
   DoCmd.TransferDatabase acLink, "ODBC Database", "ODBC;DSN=" & DSN _
      & ";UID=" & UID & ";PWD=" & PWD & ";DATABASE=" & DATABASE & ";ADDRESS=" _
      & ADDRESS, acTable, tblServerName, tblCurrentDBName, , True
End Function
'******************************* END COPY *******************************

2  save the module

3  change the UID, PWD, DSN, DATABASE, and ADDRESS variables to the correct values

4  run the ReattachTables function.

i split the functions up (even though you don't have to) just so it'd be easier for me to debug.

you need to make sure your SQL server login has rights to read from the sysobjects table on the server for this to work.

i think this does what you want, try it in a BLANK database first to see if it does.

enjoy

dovholuk
0
 

Expert Comment

by:amp072397
ID: 6742502
kullo:

You've logged in recently, kindly return to and provide feedback to dovholuk.

thanks!
amp
community support moderator
0
 

Expert Comment

by:amp072397
ID: 6758934
Points to dovholuk.

amp
community support moderator
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

786 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