I have an ms access database with 24 tables. I need to rename the tables every day from
table 1 --> table 1backup
any ideas will be appreciated.
Is it doable with VBA?
I have an ms access database with 24 tables. I need to rename the tables every day from
table 1 --> table 1backup
any ideas will be appreciated.
Is it doable with VBA?
You can:
Dim tdf As TableDef
For Each tdf In CurrentDb.TableDefs
If Left(tdf.Name, 4) <> "MSys" Then
tdf.Name = tdf.Name & "_backup"
End If
Next
CurrentDb.TableDefs("mytablename").Name = "mynewtablename"
–
Outdo I would suggest below code. It would replace newly renamed table, with the existed table, if already has existed with the new table name:
Dim tdf As TableDef
For Each tdf In CurrentDb.TableDefs
If Left(tdf.Name, 7) <> "backup_" Then
Dim newTableName As String
newTableName = "backup_" + tdf.Name
DoCmd.SetWarnings False
DoCmd.Rename newTableName, acTable, tdf.Name
DoCmd.SetWarnings True
End If
Next
© 2022 - 2024 — McMap. All rights reserved.