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
Solved

"Linked Table Manager" from within VB.

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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