link table by relative path in same folder

Alkaline

Registered User.
Local time
Today, 14:36
Joined
Sep 15, 2007
Messages
18
I want to link a table from a database that will always be located in the same folder as the current db is in. I have the following code from another thread:

DoCmd.TransferDatabase acLink, "Microsoft Access", CurrentProject.Path & "\data_be.mbd", acTable, "Persons", "Persons"

It doesnt work though. What happens if the table is already imported into the database? I have this code running from Form_Load() in the initial form that loads when I open the database.
 
If the table is already linked, you could just refresh the link using the tabledef object:
Code:
For Each tdf In CurrentDb.TableDefs
    If tdf.SourceTableName <> "" Then
        tdf.RefreshLink
    End If
Next
or if it is linked, but the link is broken you could use this:
Code:
tdf.Connect = ";DATABASE=" & strFileName

Is that what you were asking?
 

Users who are viewing this thread

Back
Top Bottom