Solved

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

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now