I need a way to catalogue all the linked tables in the Access Application then remove them and replace them with DSN-less linked tables.
I have a couple of functions that will delete all the ODBC linked tables and create DSNless connections.
What I am having problems figuring out how to do is to get the Linked table properties and store the DSN properties so that I can then recreate them as DSNless connections.
Thanks
John Fuhrman
I have a couple of functions that will delete all the ODBC linked tables and create DSNless connections.
What I am having problems figuring out how to do is to get the Linked table properties and store the DSN properties so that I can then recreate them as DSNless connections.
Code:
Public Sub DeleteODBCTableNames(Optional stLocalTableName As String)
On Error GoTo Err_DeleteODBCTableNames
Dim dbs As Database, tdf As TableDef, i As Integer
Set dbs = CurrentDb
If Len(stLocalTableName) = 0 Then
For i = dbs.TableDefs.Count - 1 To 0 Step -1
Set tdf = dbs.TableDefs(i)
If (tdf.Attributes And dbAttachedODBC) Then
dbs.TableDefs.Delete (tdf.Name)
End If
Next i
Else
dbs.TableDefs.Delete (stLocalTableName)
End If
dbs.Close
Set dbs = Nothing
Exit_DeleteODBCTableNames:
Exit Sub
Err_DeleteODBCTableNames:
MsgBox ("Error # " & str(Err.Number) & " was generated by " & Err.Source & Chr(13) & Err.Description)
Resume Exit_DeleteODBCTableNames
End Sub
Code:
Function connectToDababase(Optional m_connectionString As String) As String
'// This Function requries
'// Microsoft OLE DB Service Component 1.0 Type Library
'// Microsoft ActiveX Data Objects 2.7 Library
Dim dl As MSDASC.DataLinks
Dim cn As ADODB.Connection
Set dl = New MSDASC.DataLinks
Set cn = New ADODB.Connection
If IsMissing(m_connectionString) Then
Set cn = dl.PromptNew
Else
cn.ConnectionString = m_connectionString
dl.PromptEdit cn
End If
connectToDababase = cn.ConnectionString
End Function
Thanks
John Fuhrman