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

x
?
Solved

"Linked Table Manager" from within VB.

Posted on 2000-04-02
5
Medium Priority
?
561 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 800 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

730 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