[AccessD] A2K: Loop through Forms and close open forms

Darren DICK d.dick at uws.edu.au
Tue Jun 1 21:42:44 CDT 2004


Thanks Gustav and Drew
It's up and runnin'

This list is way cool

DD

----- Original Message ----- 
From: "Gustav Brock" <gustav at cactus.dk>
To: "Access Developers discussion and problem solving" <accessd at databaseadvisors.com>
Sent: Tuesday, June 01, 2004 5:59 PM
Subject: Re: [AccessD] A2K: Loop through Forms and close open forms


> Hi Darren
> 
> Another option is to loop through the opened forms only and close
> these one by one (if possible):
> 
> <code>
> 
> Public Function CloseAllForms() As Boolean
> 
> ' Close all open forms.
> ' Returns True if success.
> ' Reports error message for any form that could not be closed.
> '
> ' 1999-08-02. Cactus Data ApS, CPH.
> 
>   Dim lngForms      As Long
>   Dim lngForm       As Long
>   Dim strForm       As String
>   Dim strCaption    As String
>   Dim booError      As Boolean
>   Dim strMsgPrompt  As String
>   Dim strMsgTitle   As String
>   Dim lngMsgStyle   As Long
>   
>   On Error GoTo Err_CloseAllForms
>   
>   lngForms = Forms.Count
>   For lngForm = lngForms - 1 To 0 Step -1
>     ' Close forms in reverse order.
>     strForm = Forms(lngForm).Name
>     DoCmd.Close acForm, strForm
>   Next lngForm
>   
>   CloseAllForms = Not booError
>   
> Exit_CloseAllForms:
>   Exit Function
>   
> Err_CloseAllForms:
>   strCaption = Forms(lngForm).Caption
>   If Len(strCaption) > 0 Then
>     strForm = strCaption
>   End If
>   strMsgTitle = "Error"
>   strMsgPrompt = "Form '" & strForm & "' could not be closed." & vbCr & vbLf
>   strMsgPrompt = strMsgPrompt & "Error:" & Str(Err.Number) & ". " & Err.Description
>   lngMsgStyle = vbOKOnly + vbExclamation 'vbCritical
>   DoCmd.Beep
>   MsgBox strMsgPrompt, lngMsgStyle, strMsgTitle
>   booError = True
>   Resume Next
>   
> End Function
> 
> </code>
> 
> /gustav
> 
> 
> > I want to loop through the Forms collection and close any form/forms that is/are open.
> 
> > Any suggestions?
> 
> -- 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com



More information about the AccessD mailing list