G
Guest
How would I go about renaming linked tables. I'm using this code to link them
with "tbl" and want to rename them via an older convention "tblo"
The code links ok but totally skips the renaming part (except the status bar
message works, showing the last record)
Thanks,
Todd
Sub RelinkTables()
Dim myuserid, mypswrd, mydsn As String
myuserid = InputBox("Enter Replicated Database UserID", "UserID")
mypswrd = InputBox("Enter Replicated Database Password", "Password")
mydsn = InputBox("Enter ODBC Data Source Name of Replicated Database",
"DSN", "NHCC Replicated")
renameyn = MsgBox("Do you want to rename the table to the old format?",
vbYesNo, "Rename Tables")
Set dbs = CurrentDb
Set temprst = dbs.OpenRecordset("select * from LinkTables")
If temprst.EOF = False Then
temprst.MoveLast
temprst.MoveFirst
End If
'links tables from replicated database
For X = 1 To temprst.RecordCount
tbl = temprst!tablename
tblo = temprst!tablenameold
'delete table that is currently linked old and new
For Each tdf In dbs.tabledefs
If tdf.Name = tbl Then dbs.tabledefs.Delete tdf.Name
Next tdf
For Each tdf In dbs.tabledefs
If tdf.Name = tblo Then dbs.tabledefs.Delete tdf.Name
Next tdf
'relink table with
DoCmd.TransferDatabase acLink, "ODBC Database", _
"ODBC;DSN=" & mydsn & ";UID=" & myuserid & ";PWD=" & mypswrd & _
";LANGUAGE=us_english;", acTable, tbl, tbl, False, True
DoCmd.Echo True, "linking table: " & tbl
temprst.MoveNext
Next X
' Rename tables if needed
If renameyn = vbYes Then
For Each tdf In dbs.tabledefs
If tdf.Name = tbl Then
tdf.Name = Rename(tdf.Name, "", tblo)
End If
DoCmd.Echo True, "Renaming table from: " & tbl & " to: " & tblo
Next tdf
End If
temprst.Close
dbs.Close
MsgBox "Tables successfully relinked", vbOKOnly
End Sub
with "tbl" and want to rename them via an older convention "tblo"
The code links ok but totally skips the renaming part (except the status bar
message works, showing the last record)
Thanks,
Todd
Sub RelinkTables()
Dim myuserid, mypswrd, mydsn As String
myuserid = InputBox("Enter Replicated Database UserID", "UserID")
mypswrd = InputBox("Enter Replicated Database Password", "Password")
mydsn = InputBox("Enter ODBC Data Source Name of Replicated Database",
"DSN", "NHCC Replicated")
renameyn = MsgBox("Do you want to rename the table to the old format?",
vbYesNo, "Rename Tables")
Set dbs = CurrentDb
Set temprst = dbs.OpenRecordset("select * from LinkTables")
If temprst.EOF = False Then
temprst.MoveLast
temprst.MoveFirst
End If
'links tables from replicated database
For X = 1 To temprst.RecordCount
tbl = temprst!tablename
tblo = temprst!tablenameold
'delete table that is currently linked old and new
For Each tdf In dbs.tabledefs
If tdf.Name = tbl Then dbs.tabledefs.Delete tdf.Name
Next tdf
For Each tdf In dbs.tabledefs
If tdf.Name = tblo Then dbs.tabledefs.Delete tdf.Name
Next tdf
'relink table with
DoCmd.TransferDatabase acLink, "ODBC Database", _
"ODBC;DSN=" & mydsn & ";UID=" & myuserid & ";PWD=" & mypswrd & _
";LANGUAGE=us_english;", acTable, tbl, tbl, False, True
DoCmd.Echo True, "linking table: " & tbl
temprst.MoveNext
Next X
' Rename tables if needed
If renameyn = vbYes Then
For Each tdf In dbs.tabledefs
If tdf.Name = tbl Then
tdf.Name = Rename(tdf.Name, "", tblo)
End If
DoCmd.Echo True, "Renaming table from: " & tbl & " to: " & tblo
Next tdf
End If
temprst.Close
dbs.Close
MsgBox "Tables successfully relinked", vbOKOnly
End Sub