Связанные таблицы не могут быть удалены, но могут быть удалены.Добавление таблицы также добавит связанные таблицы, поэтому у меня возникли проблемы с дублированием добавлений.Я сохранил все имена, чтобы удалить сначала, а потом добавить заново (если они еще не существуют).Адрес sharepoint является частью строки подключения, поэтому я смог отфильтровать нужные мне таблицы.
Редактирование: Использование DoCmd.TransferSharePointList может привести к тому, что списки со столбцами поиска будут доступны только для чтения.Для таких списков удалите и добавьте их вручную после запуска.
Sub ChangeSPTables()
'Step through all table definitions and check if the old sharepoint address appears in the connection string
'If so, stores the name of the table, deletes all such tables, and re-adds them from the new sharepoint address
'The list is used because sometimes other tables are brought in automatically as relationships and I don't
'want extra copies or instances where the table has a 1 on the end of the name
'Will not work on things that have been renamed since they were brought in from sharepoint
'You should probably only run this on a copy of the database for saftey's sake
Dim db As dao.Database
Dim tdf As dao.TableDef
Dim MBr As VbMsgBoxResult
Dim i As Long: i = 1
Dim ListNames(1 To 20) As String 'Assumed to be 20 or less
'The old and new sharepoint addresses
Dim OldSP As String
Dim NewSP As String
OldSP = "https://old"
NewSP = "https://new"
Set db = CurrentDb
For Each tdf In db.TableDefs
If Not (tdf.Name Like "MSys*" Or tdf.Name Like "~*") And InStr(1, tdf.Connect, OldSP) > 0 Then
ListNames(i) = tdf.Name
i = i + 1
Debug.Print tdf.Name 'For review of which tables were redone
db.Execute "drop table [" & tdf.Name & "]", dbFailOnError 'drop table avoids problems with relationships between tables
End If
Next
i = 1
Do Until ListNames(i) = ""
If IsNull(DLookup("Name", "MSysObjects", "Name='" & ListNames(i) & "'")) Then 'Some things get re-added by relationship
DoCmd.TransferSharePointList acLinkSharePointList, NewSP, ListNames(i)
End If
i = i + 1
Loop
'Hide the sharepoint tables
For Each tdf In db.TableDefs
If Not (tdf.Name Like "MSys*" Or tdf.Name Like "~*") And InStr(1, tdf.Connect, NewSP) > 0 Then
Application.SetHiddenAttribute acTable, tdf.Name, True
End If
Next
Set tdf = Nothing
Set db = Nothing
End Sub