[AccessD] Close All Forms

MartyConnelly martyconnelly at shaw.ca
Fri Aug 19 16:45:56 CDT 2005


Code runs okay in Access 2003 with or without any forms open
Do you have a timer running on one of the forms.
Perhaps you can narrow it down to a specific form.

Also here is some code from solutions.mdb that you could modify

It uses database container's collection rather than form's collection.
It is used to close everything on exit and checks for open recordsets.

 Function CloseObject(strContainerName As String, intContainerType As 
Integer)
    'From the Developer Solutions database
    'Close open database objects of the specified type

    Dim dbs As Database, ctr As Container
    Dim intX As Integer
    Dim rstfind As Variant

    Set dbs = CurrentDb
    Set ctr = dbs.Containers(strContainerName)

    For intX = 0 To ctr.Documents.Count - 1
       ' DoCmd.Close intContainerType, ctr.Documents(intX).Name
       Debug.Print intContainerType, ctr.Documents(intX).Name
    Next intX
   
        For Each rstfind In CurrentDb.Recordsets
        MsgBox "Recordset Found: " & rstfind.Name
    Next rstfind

End Function
 Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
Dim bolExitDatabase As Boolean
    If MsgBox("Exit database? (No='Exit Form')", vbYesNo) = vbYes Then
        On Error Resume Next

        bolExitDatabase = True

        'Close all database objects, then exit application
        CloseObject "Tables", acTable
        CloseObject "Tables", acQuery
        CloseObject "Forms", acForm
        CloseObject "Reports", acReport
        CloseObject "Scripts", acMacro
        CloseObject "Modules", acModule

        'CloseCurrentDatabase

    Else
        DoCmd.Close
    End If

Exit_cmdExit_Click:
    Exit Sub

Err_cmdExit_Click:
    MsgBox Err.Description, , "cmdExit_Click: " & Err.Number
    Resume Exit_cmdExit_Click
End Sub

Barbara Ryan wrote:

>I don't know..... is there something new in Access 2002 that would allow
>this?
>
>Barb
>
>----- Original Message ----- 
>From: "Bobby Heid" <bheid at appdevgrp.com>
>To: "'Access Developers discussion and problem solving'"
><accessd at databaseadvisors.com>
>Sent: Friday, August 19, 2005 3:14 PM
>Subject: RE: [AccessD] Close All Forms
>
>
>  
>
>>Is it possible it is closing one of the standard access windows?
>>
>>Bobby
>>
>>-----Original Message-----
>>From: accessd-bounces at databaseadvisors.com
>>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Barbara Ryan
>>Sent: Friday, August 19, 2005 3:11 PM
>>To: Access Developers discussion and problem solving
>>Subject: Re: [AccessD] Close All Forms
>>
>>
>>It dies after the "End Function" line is executed.
>>
>>
>>-- 
>>AccessD mailing list
>>AccessD at databaseadvisors.com
>>http://databaseadvisors.com/mailman/listinfo/accessd
>>Website: http://www.databaseadvisors.com
>>    
>>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list