Solved

"Linked Table Manager" from within VB.

Posted on 2000-04-02
5
537 Views
Last Modified: 2012-06-21
My application, written in Access 2000, is supposed to have a function for linking to tables in a separate .mdb-file. This file is always the same, but can be placed i diffent locations into different drives. From the Access menu I use "Linked Table Manager". How can I do the same from a runtime application.

Odd E


0
Comment
Question by:oddeh
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:BrianWren
ID: 2677756
Linked tables have a '.Connect' property, which is not an empty string.

Loop through all of the tables in code, (setting a tableDef object), looking for the .Connect property.  When you find one, change it to the proper path, then use the .RefreshLink method of the TableDef object that you have set the .Connect property of.


     Dim t As tableDef
     Dim d as Database
     Set d = CurrentDB

     For each t in d.TableDefs
          If t.Connect <> "" THen
               ....
               ' Set the .Connect here.
               t.RefreshLink
          End If
     Next t
     Set t = Nothing
     Set d = Nothing

Brian
0
 
LVL 1

Accepted Solution

by:
wozza091599 earned 200 total points
ID: 2678089
i had the same hassle, the code from brianwren is fine i had a slightly different approch as not all my tables were in the other db so mine is probably a little longwinded i also stored the location in a small table in the local database and so had some code to prompt for the location if it changed, just simpel in a msgbox format, but i supposed you could get fancy and use a browse box, here is my code still has my table names and  fields but i'm sure you get it...
the first part gets the location from the table(strLocation) so that is like "c:\data\local\test.mdb" or whatever then just refresh all the links that you need to....

    Dim strLocation As String
    Set db = CurrentDb
    strSQL = "SELECT simpay.Data FROM simpay;"
    Set rst = CurrentDb.OpenRecordset(strSQL)
    strLocation = rst(0)
    Set rst = Nothing
   
    Set tbl = db.TableDefs("tblloans")
    tbl.Connect = ";DATABASE=" & strLocation & ""
    tbl.RefreshLink
    Set tbl = db.TableDefs("tblPayments")
    tbl.Connect = ";DATABASE=" & strLocation & ""
    tbl.RefreshLink
    Set tbl = db.TableDefs("tblSettings")
    tbl.Connect = ";DATABASE=" & strLocation & ""
    tbl.RefreshLink
    Set tbl = db.TableDefs("tblTimesheet")
    tbl.Connect = ";DATABASE=" & strLocation & ""
    tbl.RefreshLink
    Set tbl = db.TableDefs("tblYee")
    tbl.Connect = ";DATABASE=" & strLocation & ""
    tbl.RefreshLink
    Set tbl = db.TableDefs("temp")
    tbl.Connect = ";DATABASE=" & strLocation & ""
    tbl.RefreshLink
Set tbl = Nothing

hope that helps..
wozza
0
 

Author Comment

by:oddeh
ID: 2678163
Nice to have you guys. My case i much the same as wozza's. I've done some personal adjustments to the code, and it works perfect. Thanks alot wozza. My points is yours!

oddeh
0
 
LVL 9

Expert Comment

by:BrianWren
ID: 2678557
When I had this problem, I did this:



    Dim strLoc As String
    Dim d    As Database: Set d = CurrentDb

    strSQL = "SELECT simpay.Data FROM simpay;"
    Set rst = d.OpenRecordset(strSQL)
    strLoc = ";DATABASE=" & rst(0)
    Set rst = Nothing
   
    Redim Ts(6) As String
              Ts(1) =  "tblloans"
              Ts(2) =  "tblPayments"
              Ts(3) =  "tblSettings"
              Ts(4) =  "tblTimesheet"
              Ts(5) =  "tblYee"
              Ts(6) =  "temp"

    For i = 1 To 6
        Set tbl = d.TableDefs(Ts(i))
        tbl.Connect = strLocation
        tbl.RefreshLink
    Next i
    Set tbl = Nothing

Brian
0
 
LVL 1

Expert Comment

by:wozza091599
ID: 2679157
thanks oddeh, i'm just getting started on this site so i really appreciate the points, brian, your method is very neat indeed... i'll remember that... thanks...

wozza
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

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