Sorry, I forgot that the SourceTableName could not be
changed once the tabledef was added to the tabledefs
collection.
You'll have to delete the old tabledef and create a new one.
Not too big a deal, since you can retrieve the relevant
properties from the old one, delete it, create a new one and
set t--
Marsh
MVP [MS Access]
(E-Mail Removed) wrote:
>I think I am close but still have problem changing the link to a link table.
>
>Below is my code where the Sub Create_Connection creates a new linked table
>and works fine.
>
>The problem is that when i try to modify the SourceTableName property i get an
>error message "Cannot set this propertyonce the object is part of a collection
>(3268)"
>
>Basically what I want to do is change the table "Linked_Table1" 's source to
>read the rile AG151.dbf instead of AG102.dbf.
>
>Here is my code and it's made in Access 97.
>
>Sub Create_Connection()
>Dim db As Database
>Dim t As TableDef
>
>Set db = CurrentDb
>
>Set t = db.CreateTableDef("Linked_Table1")
>
>With t
>Connect = "dBase IV;DATABASE=C:\Access_Portfolio\test"
>SourceTableName = "ag102.dbf"
>End With
>
>db.TableDefs.Append t
>
>End Sub
>
>
>Sub change_connection()
>Dim db As Database
>Dim tbl As TableDef
>Dim rst As Recordset
>
>Set db = CurrentDb
>
>Set tbl = db.TableDefs("Linked_Table1")
>
>With tbl
>Connect = "dBase IV;DATABASE=C:\Access_Portfolio\test"
>SourceTableName = "ag151.dbf"
>End With
>End Sub