G
Guest
Hi
Can anyone show me how to go about rename a table in code?
SysAccountant.
Can anyone show me how to go about rename a table in code?
SysAccountant.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sprinks said:To set a single tablename via code:
Dim db As Database
Dim tdf As TableDef
Set db = CurrentDb()
db.TableDefs("OldName").Name = "NewName"
To put a "tbl" prefix on all table names:
Dim db As Database
Dim tdf As TableDef
Const conPrefix = "tbl"
Set db = CurrentDb()
For Each tdf in db.TableDefs
tdf.Name = conPrefix & tdf.Name
Next tdf
To reset names based on a table of old & new tablenames (named OldNewNames)
Dim db As Database
Dim tdf As TableDef
Dim varNewName As Variant
Set db = CurrentDb()
For Each tdf In db.TableDefs
varNewName = DLookup("[NewName]", "OldNewNames", "[OldName]='" &
tdf.Name & "'")
If Not IsNull(varNewName) Then
tdf.Name = varNewName
End If
Next tdf
Hope that helps.
Sprinks
SysAccountant said:Hi
Can anyone show me how to go about rename a table in code?
SysAccountant.
Sprinks said:To set a single tablename via code:
Dim db As Database
Dim tdf As TableDef
Set db = CurrentDb()
db.TableDefs("OldName").Name = "NewName"
To put a "tbl" prefix on all table names:
Dim db As Database
Dim tdf As TableDef
Const conPrefix = "tbl"
Set db = CurrentDb()
For Each tdf in db.TableDefs
tdf.Name = conPrefix & tdf.Name
Next tdf
To reset names based on a table of old & new tablenames (named
OldNewNames)
Dim db As Database
Dim tdf As TableDef
Dim varNewName As Variant
Set db = CurrentDb()
For Each tdf In db.TableDefs
varNewName = DLookup("[NewName]", "OldNewNames", "[OldName]='" &
tdf.Name & "'")
If Not IsNull(varNewName) Then
tdf.Name = varNewName
End If
Next tdf
Hope that helps.
Sprinks
SysAccountant said:Hi
Can anyone show me how to go about rename a table in code?
SysAccountant.
Bill Mosca said:After running Sprinks' code, you might not see the changes when you first
look in the database window. If that happens click on one of the other
objects' tabs and then back again or add this line of code to Sprinks'
Application.RefreshDatabaseWindow
--
Bill Mosca, MS Access MVP
Sprinks said:To set a single tablename via code:
Dim db As Database
Dim tdf As TableDef
Set db = CurrentDb()
db.TableDefs("OldName").Name = "NewName"
To put a "tbl" prefix on all table names:
Dim db As Database
Dim tdf As TableDef
Const conPrefix = "tbl"
Set db = CurrentDb()
For Each tdf in db.TableDefs
tdf.Name = conPrefix & tdf.Name
Next tdf
To reset names based on a table of old & new tablenames (named
OldNewNames)
Dim db As Database
Dim tdf As TableDef
Dim varNewName As Variant
Set db = CurrentDb()
For Each tdf In db.TableDefs
varNewName = DLookup("[NewName]", "OldNewNames", "[OldName]='" &
tdf.Name & "'")
If Not IsNull(varNewName) Then
tdf.Name = varNewName
End If
Next tdf
Hope that helps.
Sprinks
SysAccountant said:Hi
Can anyone show me how to go about rename a table in code?
SysAccountant.
Sprinks said:I wondered about that, Bill. Thanks.
Bill Mosca said:After running Sprinks' code, you might not see the changes when you first
look in the database window. If that happens click on one of the other
objects' tabs and then back again or add this line of code to Sprinks'
Application.RefreshDatabaseWindow
--
Bill Mosca, MS Access MVP
Sprinks said:To set a single tablename via code:
Dim db As Database
Dim tdf As TableDef
Set db = CurrentDb()
db.TableDefs("OldName").Name = "NewName"
To put a "tbl" prefix on all table names:
Dim db As Database
Dim tdf As TableDef
Const conPrefix = "tbl"
Set db = CurrentDb()
For Each tdf in db.TableDefs
tdf.Name = conPrefix & tdf.Name
Next tdf
To reset names based on a table of old & new tablenames (named
OldNewNames)
Dim db As Database
Dim tdf As TableDef
Dim varNewName As Variant
Set db = CurrentDb()
For Each tdf In db.TableDefs
varNewName = DLookup("[NewName]", "OldNewNames", "[OldName]='" &
tdf.Name & "'")
If Not IsNull(varNewName) Then
tdf.Name = varNewName
End If
Next tdf
Hope that helps.
Sprinks
:
Hi
Can anyone show me how to go about rename a table in code?
SysAccountant.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.