Solved

"Linked Table Manager" from within VB.

Posted on 2000-04-02
5
558 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
[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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

627 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