Adam Milligan
2009-09-08 23:43:02 UTC
All- I am using Access 2007 with a sql server 2008 back end via ODBC. I am
trying to dynamically change which view a linked table connects to. For
example, I have a linked table named "vwStudents" which actually connects to
"vwStudents292" in the sql database. I would like to be able to change it so
that vwStudents connects to "vwStudents291" in the backend instead. The
following code works well...
Public Sub RelinkTables(sCurrName, sProgram As String)
On Error GoTo Err_Handle
Dim tdfNew As TableDef
'Create a new table def that looks exactly like the old one
Set tdfNew = CurrentDb.CreateTableDef(sCurrName)
tdfNew.Connect = CurrentDb.TableDefs(sCurrName).Connect
'connect that table def to the correct school's data
tdfNew.SourceTableName = sCurrName & sProgram
'Append a temp table to the table defs
tdfNew.Name = sCurrName & sProgram & "Temp"
CurrentDb.TableDefs.Append tdfNew
'delete the old table def
DoCmd.DeleteObject acTable, sCurrName
'rename the temp table
CurrentDb.TableDefs(sCurrName & sProgram & "Temp").Name = sCurrName
Exit Sub
Except for the fact that before I run the code, the linked table is
updateable. After I run the code, the table is linked to the correct view,
but is read only. Is there any way to set the updateable property of a
freshly linked table? Thanks.
Adam
trying to dynamically change which view a linked table connects to. For
example, I have a linked table named "vwStudents" which actually connects to
"vwStudents292" in the sql database. I would like to be able to change it so
that vwStudents connects to "vwStudents291" in the backend instead. The
following code works well...
Public Sub RelinkTables(sCurrName, sProgram As String)
On Error GoTo Err_Handle
Dim tdfNew As TableDef
'Create a new table def that looks exactly like the old one
Set tdfNew = CurrentDb.CreateTableDef(sCurrName)
tdfNew.Connect = CurrentDb.TableDefs(sCurrName).Connect
'connect that table def to the correct school's data
tdfNew.SourceTableName = sCurrName & sProgram
'Append a temp table to the table defs
tdfNew.Name = sCurrName & sProgram & "Temp"
CurrentDb.TableDefs.Append tdfNew
'delete the old table def
DoCmd.DeleteObject acTable, sCurrName
'rename the temp table
CurrentDb.TableDefs(sCurrName & sProgram & "Temp").Name = sCurrName
Exit Sub
Except for the fact that before I run the code, the linked table is
updateable. After I run the code, the table is linked to the correct view,
but is read only. Is there any way to set the updateable property of a
freshly linked table? Thanks.
Adam