S
Sajid
Hi,
I'm using MS Access XP (mdb) with SQL Server as the
backend. The tables are connected using linked tables with
System DSN.
I'm working on a code which refreshes the linked table
based on the dsn settings. Here is the function.
' strLinkName is the name of the table as see in MS Access
' strDBName is the database name in SQL Server 2000
' strTableName is the name with the dbo. prefix
' strDSNname is the system DSN name
Public Function LinkTableDAO( _
strLinkName As String, _
strDBName As String, _
strTableName As String, _
strDSNname As String) As Boolean
' Links or re-links a single table.
' Returns True or False based on Err value.
Dim db As DAO.Database
Dim tdf As DAO.TableDef
On Error Resume Next
Set db = CurrentDb
' if the link already exists, delete it
Set tdf = db.TableDefs(strLinkName)
If Err.Number = 0 Then
' Found an existing tabledef.
db.TableDefs.Delete strLinkName
db.TableDefs.Refresh
Else
' No existing tabledef.
' Ignore error and reset.
Err.Clear
End If
' Create a new TableDef object
Set tdf = db.CreateTableDef(strLinkName)
' Set the Connect and SourceTableName
' properties to establish the link
tdf.Connect = _
"ODBC;Database=" & strDBName _
& ";DSN=" & strDSNname _
& ";Integrated Security=True"
tdf.SourceTableName = strTableName
' Append to the database's TableDefs collection
db.TableDefs.Append tdf
LinkTableDAO = (Err = 0)
End Function
This function works really great except one problem. When
I open the table strLinkName after running this function,
I still see the old data which was tied of my older DSN.
However when I close the MS Access front end and open it
again, the table shows the new data.
Please help.
Thanks,
Sajid
I'm using MS Access XP (mdb) with SQL Server as the
backend. The tables are connected using linked tables with
System DSN.
I'm working on a code which refreshes the linked table
based on the dsn settings. Here is the function.
' strLinkName is the name of the table as see in MS Access
' strDBName is the database name in SQL Server 2000
' strTableName is the name with the dbo. prefix
' strDSNname is the system DSN name
Public Function LinkTableDAO( _
strLinkName As String, _
strDBName As String, _
strTableName As String, _
strDSNname As String) As Boolean
' Links or re-links a single table.
' Returns True or False based on Err value.
Dim db As DAO.Database
Dim tdf As DAO.TableDef
On Error Resume Next
Set db = CurrentDb
' if the link already exists, delete it
Set tdf = db.TableDefs(strLinkName)
If Err.Number = 0 Then
' Found an existing tabledef.
db.TableDefs.Delete strLinkName
db.TableDefs.Refresh
Else
' No existing tabledef.
' Ignore error and reset.
Err.Clear
End If
' Create a new TableDef object
Set tdf = db.CreateTableDef(strLinkName)
' Set the Connect and SourceTableName
' properties to establish the link
tdf.Connect = _
"ODBC;Database=" & strDBName _
& ";DSN=" & strDSNname _
& ";Integrated Security=True"
tdf.SourceTableName = strTableName
' Append to the database's TableDefs collection
db.TableDefs.Append tdf
LinkTableDAO = (Err = 0)
End Function
This function works really great except one problem. When
I open the table strLinkName after running this function,
I still see the old data which was tied of my older DSN.
However when I close the MS Access front end and open it
again, the table shows the new data.
Please help.
Thanks,
Sajid