UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> CloseAllForms    

Contents

CloseAllForms Function

Closes all open Form objects unless the name of the form has been passed to the function as an exclusion (you can pass multiple form names as being 'Excluded'). Returns a byte value of 0. The reason for creating this procedure as a Function is that you have to ability to set the OnClick event of a button to: =CloseAllForms() and thus avoid a "one-liner" of [Event Procedure] VBA code to call the procedure.

Syntax

CODE
CloseAllForms([formName1][,formName2]...[,formNameX])

The optional arguments are strings that indicate form names you wish to exclude from being closed.

CODE
Public Function CloseAllForms(ParamArray Exclusions()) As Byte
'This procedure will close all the forms open except for the ones passed through
'The argument list.  Only declared as a function for flexibility.  No meaningful
'data is returned. Note that "Join" is used, which is not available in A97.
'
   Dim strExcluded As String
   Dim intX As Integer
   Const cDelimiter As String = "!" 'chose ! simply because it is not allowed in
                                    'a form name
   
   'Concatenate all the excluded form names
   strExcluded = cDelimiter & Join(Exclusions, cDelimiter) & cDelimiter
   
   'Loop all the forms and close them as appropriate
   For intX = Forms.Count - 1 To 0 Step -1
       If InStr(1, strExcluded, cDelimiter & Forms(intX).Name & cDelimiter, vbTextCompare) = 0 Then
           DoCmd.Close acForm, Forms(intX).Name, acSaveNo
       End If
   Next intX
   
End Function

Usage

VBA

CODE
CloseAllForms "form1", "form2"

Event Property

CODE
=CloseAllForms("form1","form2")

Remarks

The reason for creating this procedure as a Function is that you have to ability to set the OnClick event of a button to: =CloseAllForms() and thus avoid a "one-liner" of [Event Procedure] VBA code to call the procedure.

Forms not opened with DoCmd.OpenForm() will not be closed by this function.


Creative Commons License
CloseAllForms by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 7,861 times.  This page was last modified 03:55, 23 March 2012 by Brent Spaulding.   Disclaimers