Recherche
Recherche
Les mémos
Je débute...
Visites

 1000696 visiteurs

 2 visiteurs en ligne

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


 


Catégorie : Les mémos - Base
Page lue 5300 fois