Solved

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

Posted on 2001-06-13
3
522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

628 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