Can anyone tell me how to relink a table through code, I know you can do it through add ins-linked table manager, but I need to know how to do it through code.<br>
Thank you.
I have a table that contains the tables I want to relink. This table is bound to a form and when I click on the OK button this code is executed: (HTH)<br>
<br>
Private Sub cmdOK_Click()<br>
' Comments : read the tblConnect and re-establish connection<br>
'<br>
'***** this does NOT CREATE links, only RE-LINKS existing links ****<br>
'<br>
' Parameters : none<br>
' Created : 07/09/1998 Ron Regan<br>
' Modified : 26-May-1999 Ron Regan -instead of creating a new recordset<br>
' I now step through each record on the form<br>
' Modified :12/23/98 Ron Regan -modified the error routine to accumulate error<br>
' messages and display them at the end.<br>
' Modified : 7/22/98 Ron Regan<br>
' added a new field; environment. added a combobox<br>
' to select the environment, and code for showing<br>
' the records in that environment.<br>
' --------------------------------------------------------<br>
Dim db As Database<br>
Dim tdf As TableDef<br>
Dim strConnect As String<br>
Dim strMsg As String<br>
<br>
On Error GoTo PROC_ERR<br>
'ERH_PushStack_TSB "reconnect"<br>
1 Me.cmdClose.SetFocus<br>
2 Me.cmdOK.Enabled = False<br>
5 DoCmd.Hourglass True<br>
10 Set db = CurrentDb()<br>
25 SysCmd acSysCmdClearStatus<br>
50 'DoCmd.GoToRecord , , acFirst<br>
55 strConnect = Me.txtConnectString '!ConnectString 'save for login later<br>
60 While 1 = 1<br>
65 SysCmd acSysCmdSetStatus, Me.txtTableName & " " & Me.txtConnectString<br>
70 Set tdf = db.TableDefs(Me.txtTableName)<br>
80 tdf.Connect = Me.txtConnectString<br>
100 tdf.RefreshLink<br>
105 ' Debug.Print Me.txtTableName, tdf.Connect<br>
110 DoCmd.GoToRecord , , acNext<br>
120 Wend<br>
130 'End With<br>
<br>
Proc_End:<br>
On Error Resume Next<br>
SysCmd acSysCmdSetStatus, "Finished!"<br>
Me.cmdClose.SetFocus<br>
Set db = Nothing<br>
Set tdf = Nothing<br>
Close<br>
'ERH_PopStack_TSB<br>
DoCmd.Hourglass False<br>
If strMsg <> "" Then<br>
MsgBox strMsg, vbInformation, "Warnings were found "<br>
End If<br>
Exit Sub<br>
<br>
PROC_ERR:<br>
Select Case Err.Number<br>
<br>
Case 94, 3265 'all done<br>
Resume Proc_End<br>
Case Else<br>
strMsg = strMsg & Err.Number & " " & Err.DESCRIPTION & Me.txtTableName & vbCrLf<br>
'<br>
End Select<br>
<br>
Resume Next<br>
<br>
End Sub<br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.