Change Path of Linked Tables

D

Daniel

Good morning,

I would like to be able to change the path of all the linked tables in the
front-end of my application so that when I deliver it to our secondary site,
it is ready to go. \

I tried the following code that came from another post, but it generates an
error "Compile error: Expected: =" and yet it compiles just fine?

****

Dim db As DAO.database
Dim tdf As DAO.TableDef
Dim strPath As String
strPath = "C:\test\testdb.mdb"

Set db = CurrentDb()
Set tdf = db.TableDefs!linkedtable
tdf.Connect = ";DATABASE=" & strPath
tdf.RefreshLink
Set tdf = Nothing
Set db = Nothing
****

Is it possible to change the path to a structure/dir that does not exists on
the computer I am working on?

Thank you for your help!

Daniel
 
K

Klatuu

Yes, you can set the connect proprerty to anything. It, of course will raise
an error when it tries to connect to a backend that has an invalid path.
 
D

Daniel

When it gives me the error message it does not interupt and highlight a
specific line?
 
K

Klatuu

is linkedtable the name of a table or are you trying to use a variable?
The syntax below is correct if linkedtable is a table name, but when I tried
this syntax using it as a variable with a table name it it, I got error 3265
"Item Not Found in this collection." When I use an actual table name, it
worked. Here is a function I know works. It will refresh all the links in
your database:

Private Function ReLink(strNewPath As String) As Boolean
Dim dbs As Database
Dim tdf As TableDef
Dim intCount As Integer
Dim frmCurrentForm As Form

DoCmd.Hourglass True
On Error GoTo ErrLinkUpExit
Me.lblMsg.Visible = True
Me.cmdOK.Enabled = False

Set dbs = CurrentDb

For intCount = 0 To dbs.TableDefs.Count - 1
Set tdf = dbs.TableDefs(intCount)
If tdf.Connect <> "" Then
Me.lblMsg.Caption = "Refreshing " & tdf.NAME
DoEvents
tdf.Connect = ";DATABASE=" & strNewPath
tdf.RefreshLink
End If ' tdf.Connect <> ""
Next intCount

Set dbs = Nothing
Set tdf = Nothing

DoCmd.Hourglass False
Me.lblMsg.Caption = "All Links were refreshed!"
ReLink = True
Me.cmdOK.Enabled = True
Exit Function
 
D

Daniel

1. you were absolutely right about the table issue. I didn't realize that
about the code.

2. I used your code and as you said an error is raised when trying to link
to a non-existant path. err.number 3044. So how can force the db to accept
this path anyways?

Thank you once again for your help!

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top