UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> CloseAllForms    
(Difference between revisions)

Revision as of 16:59, 31 August 2011


Synopsis

The code will close all open Form objects unless the name of the form has been passed to the function as an exclusion. Please Note: 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
' CloseAllForms
' http://www.utteraccess.com/wiki/CloseAllForms
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date                          brief descripton
' 1.0  2011-08-31                    
'
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, intY 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

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!
Disclaimers