Automatically update linked tables MS Access

I have a tool that references linked tables from 2 other tables.  I know both the locations of the MDBs and the table names where they reside.  I am further using a macro to link the tables by using the currentproject.path variable with the assumption that all MDBs will reside in the same folder.  However, when I copy the MDBs to another folder, after linking the tables, I cannot see the data in the linked tables.  Is there anyway to automate the update linked tables to the new folder contained in "currentproject.path" in VBA?

Thanks
Vishalarya

vishalaryaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

frankyteeCommented:
delete the existing linked table and then recreate using the DoCmd.TransferSpreadsheet method, for eg:

DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel8, "whateverAcesstable", "c:\whateverfile.xls", True
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can "refresh" your table links by using the function below. If you'd like to link it to a database in the same folder as the currentdb, then do this:

Relink CurrentProject.Path & "\YourDBName.mdb"


Public Function Relink(PathToDatabase As String) As Boolean
    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef
 
    Set dbs = CurrentDb
    'Loop through the tables collection
       For Each tdf In dbs.TableDefs
        If Left(tdf.Name, 4) <> "MSYS" Then
          If Len(tdf.Connect) > 0 Then 
            tdf.Connect = ";DATABASE=" & PathToDatabase
            tdf.RefreshLink 
          End If
        End If
    Next 
  Relink = True
End Function

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.