Re: Renaming linked tables
- From: TLuebke <TLuebke@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 5 May 2006 07:07:02 -0700
Thanks Doug,
I got this snippet from someone else and have been using as is. I'll do
the suggested house keeping on it.
Todd
"Douglas J Steele" wrote:
Try putting.
dbs.TableDefs(tbl).Name = Rename(tbl, "", tblo)
after your TransferDatabase statement.
FWIW, the only declaration showing in the code you posted doesn't do what
probably you think it does.
Dim myuserid, mypswrd, mydsn As String
declares 3 variables, but only one of the (mydsn) is declared as a string.
The other two, since they have no data type associated with them, are
declared as variants. You can't "short circuit" the declaration in Access
(even though you can in some other languages). To have all 3 variables as
strings, you must use:
Dim myuserid As String, mypswrd As String, mydsn As String
BTW, where have you declared such variables as dbs, temprst, tbl and tblo?
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"TLuebke" <TLuebke@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D66B942A-EED6-40E5-9773-6270ED3622D7@xxxxxxxxxxxxxxxx
Douglas,link
I'll like to rename each table right after the linking for each one. Then
move to the next record. Any suggestions for a better way?
Thanks,
"Douglas J. Steele" wrote:
I suspect your problem is this:
If tdf.Name = tbl Then
tdf.Name = Rename(tdf.Name, "", tblo)
End If
That's only going to attempt to rename the table if the name of the is
whatever's currently stored in the variable tbl.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"TLuebke" <TLuebke@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C051BF3A-F37A-4AC7-B940-5200BE88E088@xxxxxxxxxxxxxxxx
How would I go about renaming linked tables. I'm using this code to
statusthem
with "tbl" and want to rename them via an older convention "tblo"
The code links ok but totally skips the renaming part (except the
format?",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
tblovbYesNo, "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: " &
Next tdf
End If
temprst.Close
dbs.Close
MsgBox "Tables successfully relinked", vbOKOnly
End Sub
- References:
- Renaming linked tables
- From: TLuebke
- Re: Renaming linked tables
- From: Douglas J. Steele
- Re: Renaming linked tables
- From: TLuebke
- Re: Renaming linked tables
- From: Douglas J Steele
- Renaming linked tables
- Prev by Date: Changing a newly created report from design view to preview
- Next by Date: Re: How do I add a calculated field to a report?
- Previous by thread: Re: Renaming linked tables
- Next by thread: Importing excel with dynamic columns to Access
- Index(es):
Relevant Pages
|