Public Function RenameTable(ByVal TableName As String, _
ByVal NewName As String) As Boolean
' NOTES: Function requires the following references:
'
' 1) Microsoft ActiveX Data Objects 2.x Library
' 2) Microsoft ADO Ext. 2.x for DDL and Security
On Error GoTo Err_RenameTable
Dim cnn As ADODB.Connection ' ADODB.Connection object
Dim cat As ADOX.Catalog ' ADOX.Catalog object
Dim tbl As ADOX.Table ' ADOX.Table object
Set cnn = CurrentProject.Connection ' Assign current database to connection object
Set cat = New ADOX.Catalog ' Create a new instance of the catalog object
Set cat.ActiveConnection = cnn ' Assign connection object to catalog object
Set tbl = cat.Tables(TableName) ' Assign table object to relevant table
tbl.Name = NewName ' Assign new name to table
RenameTable = True ' Function successful, table renamed
Exit_RenameTable:
' Release object variables from memory
Set tbl = Nothing ' Release ADOX.Table object from memory
Set cat = Nothing ' Release ADOX.Catalog object from memory
Set cnn = Nothing ' Release ADODB.Connection object from memory
Exit Function ' RenameTable
Err_RenameTable:
RenameTable = False ' Function failed, table not renamed
Resume Exit_RenameTable
End Function ' Rename Table