Solved

"Linked Table Manager" from within VB.

Posted on 2000-04-02
5
514 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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 the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

760 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

16 Experts available now in Live!

Get 1:1 Help Now