Solved

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

Posted on 2001-06-13
3
521 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 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