UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> Sandbox:CloseAllForms    
CloseAllForms (Sandbox)

Function Information
Syntax

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

Parameters

This CloseAllForms function takes a list of form names to exclude.

Usage Examples

VBA: CloseAllForms "form1", "form2"
Event Procecure: =CloseAllForms("form1","form2")

Supported Versions
Dependancies
Access 2000 through Access 2010. Versions prior to Access 2000 will require a replacement Join() function.
VBA (Default)
Access Object Library (Default)



Synopsis

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.

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

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 2,384 times.  This page was last modified 11:17, 20 March 2012 by Jack Leach.   Disclaimers