Supprimer les objets
Pour supprimer des objets comme les requêtes, formulaires, états, macros et autres modules d'une base externe, il faut passer par les collections.
La structure de la fonction est telle, qu'il sera simple de commenter la partie non utile ou non souhaitée.
Téléchargez la base contenant la fonction.
Public Function DelAllObject(sBase As String)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~ Usage :
'~~ DelAllObject "C:MesFichiersMaBase.mdb"
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim acApp As Object
Dim Dbs As DAO.Database, Doc As DAO.Document
Dim Ctn As Container, Qry As QueryDef
Dim sDocName As String
Set acApp = CreateObject("Access.Application")
acApp.OpenCurrentDatabase sBase
Set Dbs = acApp.CurrentDb
With Dbs
'// Query
For Each Qry In .QueryDefs
If Left(Qry.Name, 1) <> "~" Then
acApp.DoCmd.DeleteObject acQuery, Qry.Name
End If
Next
.QueryDefs.Refresh
End With
With Dbs.Containers
'// Forms
For Each Doc In !Forms.Documents
sDocName = Doc.Name
acApp.DoCmd.DeleteObject acForm, sDocName
Next
!Forms.Documents.Refresh
'// Reports
For Each Doc In !Reports.Documents
sDocName = Doc.Name
acApp.DoCmd.DeleteObject acReport, sDocName
Next
!Reports.Documents.Refresh
'// Scripts
For Each Doc In !Scripts.Documents
sDocName = Doc.Name
acApp.DoCmd.DeleteObject acMacro, sDocName
Next
!Scripts.Documents.Refresh
'// Module
For Each Doc In !Modules.Documents
sDocName = Doc.Name
acApp.DoCmd.DeleteObject acModule, sDocName
Next
!Modules.Documents.Refresh
End With
'// Fermer et libérer
acApp.CloseCurrentDatabase
acApp.Quit: Set acApp = Nothing
Dbs.Close: Set Dbs = Nothing
End Function
Dernière modification : 10/06/2015 14:56
Catégorie : - Base
Page lue 7316 fois