1 1 1 1 1 1 1 1 1 1 Rating 0.00 (0 Votes)

Problemstellung:

Für 32Bit und 64Bit Office Versionen

Wie kann ich alle geöffneten Formulare mit einem Mal schließen?

Public Sub CloseAllForms()
    Dim frm As AccessObject, db As Object
    Set db = Application.CurrentProject
       
    For Each frm In db.AllForms
        If frm.IsLoaded = True Then
            DoCmd.Close acForm, frm.Name, acSaveYes
        End If
    Next frm
End Sub

Einfach Prozedur aufrufen und alle geöffneten Formulare werden geschlossen.

Aufruf:

Call CloseAllForms

Es gibt noch eine weitere Möglichkeit nur bestimmte Formulare zuschließen über die Tag-Eigenschaft.
z.B.  sollen alle Formulare geschlossen werden die in der Tag-Eigenschaft ein "X" haben.
Dann sähe der Code so aus:

Public Sub CloseAllForms2(sTag As String)
    Dim frm As AccessObject, db As Object
    Dim frmSet As Form
   
    Set db = Application.CurrentProject
       
    For Each frm In db.AllForms
        If frm.IsLoaded = True Then
            Set frmSet = Forms(frm.Name)
            If frmSet.Tag = sTag Then DoCmd.Close acForm, frm.Name, acSaveYes
        End If
    Next frm
End Sub

Aufruf:

Call CloseAllForms2("X")
 

 

Ähnliche Artikel