We use this is Access97:
First: Module
Option Compare Database
Option Explicit
'In order for the program to run successfully, the ODBC System Data source
'should appear as: Amisys-Live
'
'The error code associated with this problem is 3151. To fix this problem:
'
'Start->Settings->ControlPanel->ODBC Data Sources->System DSN
'If there are any spaces in the data source, click the configure button
'and delete the spaces
'
'
Function RelinkOne()
On Error GoTo Errmsg:
'Relinks one of the Amisys Attached tables
'which will make Access recognize the current machine's user
Dim db As Database, tdf As TableDef
Dim rst As Recordset
Dim mytype As Integer
Dim myname As String
Dim mynewname As String
Dim foreignname As String
Dim sql As String
Dim mymess As String
'Dim sngStart As Single
'Dim sngEnd As Single
'Dim seconds As Single
'sngStart = Timer
Set db = CurrentDb
Set rst = db.OpenRecordset("msysObjects"
'Loop through System Objects table until finding the first attached table
DoCmd.Hourglass True
rst.MoveFirst
Do Until rst.EOF
mytype = rst![Type]
If mytype = 4 Then 'Relink just one table then end program
myname = rst![Name]
mynewname = myname & "a"
foreignname = rst![foreignname]
Set tdf = db.TableDefs(myname)
tdf.Name = mynewname
Set tdf = db.CreateTableDef(myname)
tdf.Connect = "ODBC;DSN=AMISYS-LIVE;DATABASE=;;"
tdf.SourceTableName = foreignname
db.TableDefs.Append tdf
sql = "Drop table " & mynewname & ";"
db.Execute sql
DoCmd.Hourglass False
'sngEnd = Timer
'seconds = sngEnd - sngStart
'MsgBox "This program took " & seconds & " seconds"
Exit Function
End If
rst.MoveNext
Loop
DoCmd.Hourglass False
Set db = Nothing
Errmsg:
Set tdf = db.TableDefs(mynewname)
tdf.Name = myname
mymess = "Error code " & Err & "." & Chr(10) & Chr(13) & Chr(10) & Chr(13)
mymess = mymess & "There has been an error in relinking the attached Amisys tables. "
mymess = mymess & "Please call the IM department for assistance."
MsgBox mymess, vbOKOnly, "Important!"
DoCmd.Hourglass False
Exit Function
End Function
Second: Autoexec Macro
Run Code =relinkone()