Закрыть все открытые формы |
|
|
Автор Daniel Pineault
|
29.04.2023 г. |
В некоторых случаях может быть полезно закрыть все формы в базе данных. И желательно одной командой.
Концепция такая: мы перебираем все формы (Application.Forms), и закрываем их (DoCmd.Close).
'--------------------------------------------------------------------------------------- ' Procedure : CloseAllOpenForms ' Author : Daniel Pineault, CARDA Consultants Inc. ' Website : http://www.cardaconsultants.com ' Purpose : Close all the currently open Forms in the database ' Copyright : The following is release as Attribution-ShareAlike 4.0 International ' (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/ ' Req'd Refs: None required ' ' Usage: ' ~~~~~~ ' ? CloseAllOpenForms ' Returns -> True => Closed all Forms successfully ' False => A problem occurred ' ' Revision History: ' Rev Date(yyyy/mm/dd) Description ' ************************************************************************************** ' 1 2015-02-17 Initial Release ' 2 2023-02-09 Update variable naming, Error handler, copyright ' 3 2023-03-13 Changed approach as For each frm in frms skips ' objects '--------------------------------------------------------------------------------------- Function CloseAllOpenForms() As Boolean On Error GoTo Error_Handler Dim i As Long For i = Application.Forms.Count - 1 To 0 Step -1 DoCmd.Close acForm, Forms(i).Name, acSaveNo Next i CloseAllOpenForms = True Error_Handler_Exit: On Error Resume Next Exit Function Error_Handler: MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _ "Error Source: CloseAllOpenForms" & vbCrLf & _ "Error Number: " & Err.Number & vbCrLf & _ "Error Description: " & Err.Description & _ Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _ , vbOKOnly + vbCritical, "An Error has Occurred!" Resume Error_Handler_Exit End Function Примеры использования Чтобы использовать функцию, мы просто делаем:
Call CloseAllOpenForms Или If CloseAllOpenForms= True Then '... End If Источник MS Access – VBA – Close All Open Forms
Просмотров: 1166
Ваш коментарий будет первым | | |