Hi. I was given the following Access VBA code to rename a backend column in a split Access database solution. What similar code would I use to rename a table? Thanks
Public Sub RenameColumn(ByVal tableName As String, ByVal oldName As String, ByVal newName As String)
Dim dbName As String
dbName = GetLinkedDBName(tableName)
Dim db As DAO.Database
Set db = OpenDatabase(dbName)
Dim tdf As DAO.TableDef
Set tdf = db.TableDefs(tableName)
If (ExistInCollection(oldName, tdf.Fields)) Then
Dim field As DAO.field
Set field = tdf.Fields(oldName)
field.Name = newName
End If
End Sub
Public Function ExistInCollection(ByVal key As String, ByRef col As Object) As Boolean
ExistInCollection = ExistInCollectionByVal(key, col) Or ExistInCollectionByRef(key, col)
End Function
Private Function ExistInCollectionByVal(ByVal key As String, ByRef col As Object) As Boolean
On Error GoTo Error
Dim item As Variant
item = col(key)
ExistInCollectionByVal = True
Exit Function
Error:
ExistInCollectionByVal = False
End Function
Private Function ExistInCollectionByRef(ByVal key As String, ByRef col As Object) As Boolean
On Error GoTo Error
Dim item As Variant
Set item = col(key)
ExistInCollectionByRef = True
Exit Function
Error:
ExistInCollectionByRef = False
End Function