Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-06-13
3
Medium Priority
?
524 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 800 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

704 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