Use the CompactRepair method of the Application object to compact and repair the database
Sub CompactRepairDB()
Dim strFilePath As String
strFilePath = CurrentProject.Path
Application.CompactRepair strFilePath & "\B.accdb", _
strFilePath & "\S.accdb", True
End Sub